-
This commit is contained in:
@@ -20,6 +20,14 @@ message LoginResponse {
|
|||||||
required Account account = 1;
|
required Account account = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message PersonSelectRequest {
|
||||||
|
required int32 person_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message PersonSelectResponse {
|
||||||
|
required Person person = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message ErrorResponse {
|
message ErrorResponse {
|
||||||
required int32 code = 1;
|
required int32 code = 1;
|
||||||
required string message = 2;
|
required string message = 2;
|
||||||
|
|||||||
@@ -51,9 +51,28 @@
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"id":"person", "type":"haxework.gui.VGroupView",
|
"id":"person", "type":"ru.m.armageddon.client.frames.PersonFrame",
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"},
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
|
||||||
"pWidth":100, "pHeight":100, "layoutMargin":3
|
"pWidth":100, "pHeight":100, "layoutMargin":3, "paddings":10,
|
||||||
|
"views":[
|
||||||
|
{
|
||||||
|
"id":"list", "type":"haxework.gui.list.VListView",
|
||||||
|
"renderer":{
|
||||||
|
"type":"ru.m.armageddon.client.frames.person.PersonRenderer"
|
||||||
|
},
|
||||||
|
"scroll":{
|
||||||
|
"type":"haxework.gui.list.VScrollView",
|
||||||
|
"skin":{"type":"haxework.gui.list.VScrollSkin"}
|
||||||
|
},
|
||||||
|
"pWidth":100, "pHeight":100, "layoutMargin":5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id":"game", "type":"haxework.gui.SpriteView",
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
|
||||||
|
"pWidth":100, "pHeight":100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.armageddon.client;
|
package ru.m.armageddon.client;
|
||||||
|
|
||||||
|
import ru.m.armageddon.client.data.GameData;
|
||||||
import haxework.frame.IFrameSwitcher;
|
import haxework.frame.IFrameSwitcher;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.armageddon.client.frames.AuthFrame;
|
import ru.m.armageddon.client.frames.AuthFrame;
|
||||||
@@ -31,6 +32,7 @@ class Client {
|
|||||||
switcher = GuiBuilder.build(form, {listener:this});
|
switcher = GuiBuilder.build(form, {listener:this});
|
||||||
new Root(switcher);
|
new Root(switcher);
|
||||||
|
|
||||||
|
Provider.setFactory(GameData, GameData);
|
||||||
Provider.set(IFrameSwitcher, switcher);
|
Provider.set(IFrameSwitcher, switcher);
|
||||||
Provider.set(IConnection, new FlashConnection("localhost", 5000));
|
Provider.set(IConnection, new FlashConnection("localhost", 5000));
|
||||||
|
|
||||||
|
|||||||
9
src/client/haxe/ru/m/armageddon/client/data/GameData.hx
Executable file
9
src/client/haxe/ru/m/armageddon/client/data/GameData.hx
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
package ru.m.armageddon.client.data;
|
||||||
|
|
||||||
|
import ru.m.armageddon.proto.Person;
|
||||||
|
import ru.m.armageddon.proto.Account;
|
||||||
|
|
||||||
|
class GameData {
|
||||||
|
public var account:Account;
|
||||||
|
public var person:Person;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.armageddon.client.frames;
|
package ru.m.armageddon.client.frames;
|
||||||
|
|
||||||
|
import ru.m.armageddon.client.data.GameData;
|
||||||
import flash.net.SharedObject;
|
import flash.net.SharedObject;
|
||||||
import ru.m.armageddon.proto.ErrorResponse;
|
import ru.m.armageddon.proto.ErrorResponse;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
@@ -62,7 +63,8 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
so.setProperty("login", loginInput.text);
|
so.setProperty("login", loginInput.text);
|
||||||
so.setProperty("password", passwordInput.text);
|
so.setProperty("password", passwordInput.text);
|
||||||
so.flush();
|
so.flush();
|
||||||
Provider.get(IFrameSwitcher).change("person");
|
Provider.get(GameData).account = packet.account;
|
||||||
|
Provider.get(IFrameSwitcher).change(PersonFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onErrorResponse(packet:ErrorResponse):Void {
|
public function onErrorResponse(packet:ErrorResponse):Void {
|
||||||
|
|||||||
50
src/client/haxe/ru/m/armageddon/client/frames/PersonFrame.hx
Executable file
50
src/client/haxe/ru/m/armageddon/client/frames/PersonFrame.hx
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
package ru.m.armageddon.client.frames;
|
||||||
|
|
||||||
|
import haxework.frame.IFrameSwitcher;
|
||||||
|
import protohx.MessageUtils;
|
||||||
|
import ru.m.armageddon.proto.PersonSelectResponse;
|
||||||
|
import ru.m.armageddon.proto.PersonSelectRequest;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import protohx.Message;
|
||||||
|
import ru.m.armageddon.core.connect.IConnection;
|
||||||
|
import ru.m.armageddon.client.frames.person.PersonView;
|
||||||
|
import ru.m.armageddon.client.data.GameData;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import ru.m.armageddon.proto.Person;
|
||||||
|
import haxework.gui.list.VListView;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import ru.m.armageddon.client.frames.person.PersonRenderer;
|
||||||
|
|
||||||
|
class PersonFrame extends HGroupView implements IPacketHandler implements ListViewListener<PersonView, Person> {
|
||||||
|
|
||||||
|
private static inline var TAG = "PersonFrame";
|
||||||
|
|
||||||
|
public static inline var ID = "person";
|
||||||
|
|
||||||
|
private var list:VListView<PersonView, Person>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init() {
|
||||||
|
list = findViewById("list");
|
||||||
|
list.dispatcher.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow() {
|
||||||
|
list.data = Provider.get(GameData).account.persons;
|
||||||
|
Provider.get(IConnection).packetHandler = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onListItemClick(item:ListItem<PersonView, Person>):Void {
|
||||||
|
Provider.get(IConnection).send(new PersonSelectRequest().setPersonId(item.data.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPersonSelectResponse(packet:PersonSelectResponse):Void {
|
||||||
|
Provider.get(GameData).person = packet.person;
|
||||||
|
Provider.get(IFrameSwitcher).change("game");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPacket(packet:Message):Void {}
|
||||||
|
}
|
||||||
16
src/client/haxe/ru/m/armageddon/client/frames/person/PersonRenderer.hx
Executable file
16
src/client/haxe/ru/m/armageddon/client/frames/person/PersonRenderer.hx
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
package ru.m.armageddon.client.frames.person;
|
||||||
|
|
||||||
|
import ru.m.armageddon.proto.Person;
|
||||||
|
import haxework.gui.list.VListView;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
|
||||||
|
class PersonRenderer implements IRenderer<VListView<PersonView, Person>, PersonView, Person> {
|
||||||
|
|
||||||
|
public function factory():ListItem<PersonView, Person> {
|
||||||
|
return {view:new PersonView()};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render(list:VListView<PersonView, Person>, item:ListItem<PersonView, Person>):Void {
|
||||||
|
item.view.person = item.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/client/haxe/ru/m/armageddon/client/frames/person/PersonView.hx
Executable file
29
src/client/haxe/ru/m/armageddon/client/frames/person/PersonView.hx
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
package ru.m.armageddon.client.frames.person;
|
||||||
|
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import ru.m.armageddon.proto.Person;
|
||||||
|
import haxework.gui.skin.ColorSkin;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
|
||||||
|
class PersonView extends HGroupView {
|
||||||
|
|
||||||
|
public var person(default,set):Person;
|
||||||
|
|
||||||
|
private var nameLabel:LabelView;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
pWidth = 100;
|
||||||
|
height = 50;
|
||||||
|
skin = new ColorSkin(0xffffff);
|
||||||
|
|
||||||
|
nameLabel = new LabelView();
|
||||||
|
addView(nameLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_person(value:Person):Person {
|
||||||
|
this.person = value;
|
||||||
|
nameLabel.text = this.person.name;
|
||||||
|
return this.person;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import ru.m.armageddon.core.connect.IConnection;
|
|||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import ru.m.armageddon.proto.LoginRequest;
|
import ru.m.armageddon.proto.LoginRequest;
|
||||||
import ru.m.armageddon.proto.LoginResponse;
|
import ru.m.armageddon.proto.LoginResponse;
|
||||||
|
import ru.m.armageddon.proto.PersonSelectRequest;
|
||||||
|
import ru.m.armageddon.proto.PersonSelectResponse;
|
||||||
import ru.m.armageddon.proto.ErrorResponse;
|
import ru.m.armageddon.proto.ErrorResponse;
|
||||||
|
|
||||||
class PacketBuilder implements IPacketBuilder {
|
class PacketBuilder implements IPacketBuilder {
|
||||||
@@ -14,7 +16,9 @@ class PacketBuilder implements IPacketBuilder {
|
|||||||
],
|
],
|
||||||
0x01 => [
|
0x01 => [
|
||||||
0x0001 => LoginRequest,
|
0x0001 => LoginRequest,
|
||||||
0x0002 => LoginResponse
|
0x0002 => LoginResponse,
|
||||||
|
0x0003 => PersonSelectRequest,
|
||||||
|
0x0004 => PersonSelectResponse
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class FlashConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onSocketData(_):Void {
|
private function onSocketData(_):Void {
|
||||||
|
if (socket.bytesAvailable == 0) return;
|
||||||
var family = socket.readByte();
|
var family = socket.readByte();
|
||||||
var id = socket.readByte();
|
var id = socket.readByte();
|
||||||
var length = socket.readShort();
|
var length = socket.readShort();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import sys.db.Mysql;
|
|||||||
import sys.db.Connection;
|
import sys.db.Connection;
|
||||||
|
|
||||||
typedef DbPerson = {
|
typedef DbPerson = {
|
||||||
|
@:optional var a_id:Int;
|
||||||
var p_id:Int;
|
var p_id:Int;
|
||||||
var p_name:String;
|
var p_name:String;
|
||||||
}
|
}
|
||||||
@@ -26,13 +27,23 @@ class Db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getAccount(login:String, password:String):Null<Account> {
|
public function getAccount(login:String, password:String):Null<Account> {
|
||||||
var rset = db.request("SELECT p.id AS p_id, p.name AS p_name FROM account AS a LEFT JOIN person AS p ON(a.id=p.account_id) WHERE a.login='" + login + "' AND a.password='" + password + "'");
|
var rset = db.request("SELECT a.id AS a_id, p.id AS p_id, p.name AS p_name FROM account AS a LEFT OUTER JOIN person AS p ON(a.id=p.account_id) WHERE a.login='" + login + "' AND a.password='" + password + "'");
|
||||||
if (!rset.hasNext()) return null;
|
if (!rset.hasNext()) return null;
|
||||||
var account = new Account().setLogin(login);
|
var account = new Account().setLogin(login);
|
||||||
while (rset.hasNext()) {
|
while (rset.hasNext()) {
|
||||||
var data:DbPerson = rset.next();
|
var data:DbPerson = rset.next();
|
||||||
|
account.setId(data.a_id);
|
||||||
|
if (data.p_name != null) {
|
||||||
account.addPersons(new Person().setId(data.p_id).setName(data.p_name));
|
account.addPersons(new Person().setId(data.p_id).setName(data.p_name));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPerson(account_id:Int, person_id:Int):Null<Person> {
|
||||||
|
var rset = db.request("SELECT id AS p_id, name AS p_name FROM person WHERE id=" + person_id + " AND account_id=" + account_id);
|
||||||
|
if (!rset.hasNext()) return null;
|
||||||
|
var data:DbPerson = rset.next();
|
||||||
|
return new Person().setId(data.p_id).setName(data.p_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.armageddon.server.session;
|
package ru.m.armageddon.server.session;
|
||||||
|
|
||||||
|
import ru.m.armageddon.proto.PersonSelectResponse;
|
||||||
|
import ru.m.armageddon.proto.PersonSelectRequest;
|
||||||
import ru.m.armageddon.proto.Account;
|
import ru.m.armageddon.proto.Account;
|
||||||
import ru.m.armageddon.core.connect.neko.NekoConnection;
|
import ru.m.armageddon.core.connect.neko.NekoConnection;
|
||||||
import ru.m.armageddon.proto.ErrorResponse;
|
import ru.m.armageddon.proto.ErrorResponse;
|
||||||
@@ -45,6 +47,16 @@ class Session implements IConnectionHandler implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onPersonSelectRequest(packet:PersonSelectRequest):Void {
|
||||||
|
var db = new Db();
|
||||||
|
var person = db.getPerson(account.id, packet.personId);
|
||||||
|
if (person != null) {
|
||||||
|
connection.send(new PersonSelectResponse().setPerson(person));
|
||||||
|
} else {
|
||||||
|
connection.send(new ErrorResponse().setCode(404).setMessage("Person not found"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onPacket(packet:Message):Void {
|
public function onPacket(packet:Message):Void {
|
||||||
trace("Unknown packet: " + Type.getClassName(Type.getClass(packet)).split(".").pop());
|
trace("Unknown packet: " + Type.getClassName(Type.getClass(packet)).split(".").pop());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user