Exemplo n.º 1
0
        public void GetMessage()
        {
            do
            {
                stream.Flush();
                byte[] bytes = new byte[2048];
                stream.Read(bytes, 0, bytes.Length);
                NetData message = NetData.RecoverBytes(bytes);

                if (message.number > lastMessageNumber)
                {
                    if (ServerHandler.clients.Contains(message.sender.ID))
                    {
                        if ((ServerHandler.clients[message.sender.ID] as NetUser).tcpConnection == null)
                        {
                            netUser = ServerHandler.clients[message.sender.ID] as NetUser;
                            netUser.tcpConnection = this;
                            NetUser.OnUserConnectedTCP(message.sender);
                        }
                    }
                    else
                    {
                        netUser = new NetUser(message.sender);
                        netUser.tcpConnection = this;
                        ServerHandler.AddConnection(netUser);
                        NetUser.OnUserConnectedTCP(message.sender);
                    }

                    if (netUser.info == null)
                    {
                        netUser.info = NetUser.server.GetUserData(message.sender.ID);
                    }
                    if (netUser.info == null)
                    {
                        netUser.info = ServerHandler.createUserBD(message.sender);
                    }

                    NetUser.OnTcpMessageHandleCallback(bytes, message, netUser);
                    lastMessageNumber = message.number;
                }
            }while (stream.DataAvailable);
        }