示例#1
0
        private void HandleClient(TcpClient client)
        {
            Thread child = new Thread(() => {
                Session session = new Session(this, client);

                while(Running) {
                    byte[] data = new byte[2];

                    try {
                        if(client.Client.Receive(data) == 0) break;
                    } catch(SocketException) {
                        break;
                    }

                    int headerLength = data[0] << 8 | data[1];

                    data = new byte[headerLength];
                    client.Client.Receive(data);
                    bnet.protocol.Header header = bnet.protocol.Header.ParseFrom(data);

                    data = new byte[header.Size];
                    if(header.Size > 0) {
                        client.Client.Receive(data);
                    }

                    session.HandlePacket(header, data);
                }

                Debug.WriteLine("INFO Client {0} disconnected", client.Client.RemoteEndPoint);
                client.Close();
            });

            child.IsBackground = true;
            child.Start();
        }
示例#2
0
        public GameSession(Server server, Session session)
        {
            Server = server;
            Session = session;

            Account = new Account() { // TODO: load account from DB
                ID = 1,
                Email = "*****@*****.**",
                LastUpdate = DateTime.Now
            };

            SubscriptionHandler = new SubscriptionHandler(this);
            VersionHandler = new VersionHandler(this);
            AccountHandler = new AccountHandler(this);
            StoreHandler = new StoreHandler(this);
        }
示例#3
0
文件: Server.cs 项目: Goz3rr/Hestia
 public IGameSession Connect(Session session)
 {
     return new GameSession(this, session);
 }