-
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@ target/
|
|||||||
src-gen/
|
src-gen/
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
|
*.ids
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<meta title="Armageddon" package="ru.m.armageddon" version="0.0.0" company="m"/>
|
<meta title="Armageddon" package="ru.m.armageddon" version="0.0.0" company="m"/>
|
||||||
<app main="ru.m.armageddon.Armageddon" path="target" file="armageddon"/>
|
<app main="ru.m.armageddon.client.Client" path="target" file="armageddon"/>
|
||||||
<source path="src/haxe"/>
|
<source path="src/common/haxe"/>
|
||||||
|
<source path="src/client/haxe"/>
|
||||||
<source path="src-gen/haxe"/>
|
<source path="src-gen/haxe"/>
|
||||||
<haxelib name="openfl"/>
|
<haxelib name="openfl"/>
|
||||||
<haxelib name="protohx"/>
|
<haxelib name="protohx"/>
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
message Foo {
|
message User {
|
||||||
required string bar = 1;
|
required int32 id = 1;
|
||||||
|
required string login = 2;
|
||||||
|
required string nickname = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LoginRequest {
|
||||||
|
required string login = 1;
|
||||||
|
required string password = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LoginResponse {
|
||||||
|
required User user = 1;
|
||||||
}
|
}
|
||||||
6
server.hxml
Executable file
6
server.hxml
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
-main ru.m.armageddon.server.Server
|
||||||
|
-lib protohx
|
||||||
|
-cp src/common/haxe
|
||||||
|
-cp src/server/haxe
|
||||||
|
-cp src-gen/haxe
|
||||||
|
-neko target/server.n
|
||||||
15
sql/init.sql
Executable file
15
sql/init.sql
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
-- mysql -u shmyga -pxkbp8jh9z2 armageddon --protocol TCP
|
||||||
|
CREATE USER 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
|
||||||
|
|
||||||
|
DROP DATABASE IF EXISTS armageddon;
|
||||||
|
CREATE DATABASE IF NOT EXISTS armageddon;
|
||||||
|
GRANT ALL ON armageddon.* TO 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
|
||||||
|
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS armageddon.users;
|
||||||
|
CREATE TABLE IF NOT EXISTS armageddon.users (
|
||||||
|
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
login VARCHAR(255) UNIQUE,
|
||||||
|
password VARCHAR(32)
|
||||||
|
);
|
||||||
|
INSERT INTO armageddon.users (login,password) VALUES('shmyga', 'd48cc4eb42c058869ae90daef9606e43');
|
||||||
53
src/client/haxe/ru/m/armageddon/client/Client.hx
Executable file
53
src/client/haxe/ru/m/armageddon/client/Client.hx
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
package ru.m.armageddon.client;
|
||||||
|
|
||||||
|
import haxe.io.Bytes;
|
||||||
|
import flash.events.Event;
|
||||||
|
import flash.events.SecurityErrorEvent;
|
||||||
|
import flash.events.IOErrorEvent;
|
||||||
|
import haxe.io.BytesOutput;
|
||||||
|
import haxework.log.TraceLogger;
|
||||||
|
import flash.net.Socket;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Client {
|
||||||
|
|
||||||
|
private static inline var TAG = "Armageddon";
|
||||||
|
|
||||||
|
public static function main() {
|
||||||
|
L.push(new TraceLogger());
|
||||||
|
L.d(TAG, Meta.getVersion());
|
||||||
|
new Client();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private var socket:Socket;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
|
||||||
|
socket = new Socket();
|
||||||
|
socket.addEventListener(IOErrorEvent.IO_ERROR, function(error):Void {
|
||||||
|
L.e("SocketLogger", "", error);
|
||||||
|
});
|
||||||
|
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(error):Void {
|
||||||
|
L.e("SocketLogger", "", error);
|
||||||
|
});
|
||||||
|
//socket.addEventListener(Event.CLOSE, closeHandler);
|
||||||
|
socket.addEventListener(Event.CONNECT, onConnect);
|
||||||
|
//socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
|
||||||
|
//socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
|
||||||
|
//socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
|
||||||
|
socket.connect("localhost", 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnect(_) {
|
||||||
|
var request = new LoginRequest();
|
||||||
|
request.login = "shmyga";
|
||||||
|
request.password = "xkbp8jh9z2";
|
||||||
|
var out = new BytesOutput();
|
||||||
|
request.writeTo(out);
|
||||||
|
var bytes = out.getBytes();
|
||||||
|
socket.writeShort(bytes.length);
|
||||||
|
socket.writeBytes(cast bytes.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/common/haxe/ru/m/armageddon/z.hx
Executable file
3
src/common/haxe/ru/m/armageddon/z.hx
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
package ru.m.armageddon;
|
||||||
|
interface z {
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package ru.m.armageddon;
|
|
||||||
|
|
||||||
import haxe.io.BytesOutput;
|
|
||||||
import haxework.log.TraceLogger;
|
|
||||||
|
|
||||||
class Armageddon {
|
|
||||||
|
|
||||||
private static inline var TAG = "Armageddon";
|
|
||||||
|
|
||||||
public static function main() {
|
|
||||||
L.push(new TraceLogger());
|
|
||||||
L.d(TAG, Meta.getVersion());
|
|
||||||
|
|
||||||
var foo = new Foo();
|
|
||||||
foo.bar = "test";
|
|
||||||
|
|
||||||
var out = new BytesOutput();
|
|
||||||
foo.writeTo(out);
|
|
||||||
|
|
||||||
var foo2 = new Foo();
|
|
||||||
foo2.mergeFrom(out.getBytes());
|
|
||||||
|
|
||||||
L.d(TAG, foo2.bar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
80
src/server/haxe/ru/m/armageddon/server/Server.hx
Executable file
80
src/server/haxe/ru/m/armageddon/server/Server.hx
Executable file
@@ -0,0 +1,80 @@
|
|||||||
|
package ru.m.armageddon.server;
|
||||||
|
|
||||||
|
import sys.db.Mysql;
|
||||||
|
|
||||||
|
import neko.Lib;
|
||||||
|
import sys.net.Socket;
|
||||||
|
import neko.net.ThreadServer;
|
||||||
|
import haxe.io.Bytes;
|
||||||
|
|
||||||
|
typedef Client = {
|
||||||
|
var id:Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef Message = {
|
||||||
|
var str:String;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Server extends ThreadServer<Client, Message> {
|
||||||
|
// create a Client
|
||||||
|
override function clientConnected(s:Socket):Client {
|
||||||
|
var num = Std.random(100);
|
||||||
|
Lib.println("client " + num + " is " + s.peer());
|
||||||
|
return { id: num };
|
||||||
|
}
|
||||||
|
|
||||||
|
override function clientDisconnected(c:Client) {
|
||||||
|
Lib.println("client " + Std.string(c.id) + " disconnected");
|
||||||
|
}
|
||||||
|
|
||||||
|
override function readClientMessage(c:Client, buf:Bytes, pos:Int, len:Int) {
|
||||||
|
Lib.println("client " + Std.string(c.id) + " message");
|
||||||
|
var request = new LoginRequest();
|
||||||
|
request.mergeFrom(buf);
|
||||||
|
Lib.println(request.login);
|
||||||
|
Lib.println(request.password);
|
||||||
|
|
||||||
|
// find out if there's a full message, and if so, how long it is.
|
||||||
|
var complete = false;
|
||||||
|
var cpos = pos;
|
||||||
|
while (cpos < (pos + len) && !complete) {
|
||||||
|
//check for a period/full stop (i.e.: "." ) to signify a complete message
|
||||||
|
complete = (buf.get(cpos) == 46);
|
||||||
|
cpos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no full message
|
||||||
|
if (!complete) return null;
|
||||||
|
|
||||||
|
// got a full message, return it
|
||||||
|
var msg:String = buf.readString(pos, cpos - pos);
|
||||||
|
return {msg: {str: msg}, bytes: cpos - pos};
|
||||||
|
}
|
||||||
|
|
||||||
|
override function clientMessage(c:Client, msg:Message) {
|
||||||
|
Lib.println(c.id + " sent: " + msg.str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function main() {
|
||||||
|
var server = new Server();
|
||||||
|
server.run("localhost", 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Db {
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
var cnx = Mysql.connect({
|
||||||
|
host : "localhost",
|
||||||
|
port : 3306,
|
||||||
|
user : "shmyga",
|
||||||
|
pass : "xkbp8jh9z2",
|
||||||
|
socket : null,
|
||||||
|
database : "armageddon"
|
||||||
|
});
|
||||||
|
|
||||||
|
cnx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user