Пример #1
0
        public void SendPlayerConnect()
        {
            ClientMessage message = CreateClientMessage();

            message.playerConnect = new io.gamemachine.messages.PlayerConnect();
            Write(Serialize(message));
        }
Пример #2
0
        private byte[] Serialize(ClientMessage message)
        {
            MemoryStream stream = new MemoryStream();

            Serializer.SerializeWithLengthPrefix(stream, message, PrefixStyle.Base128);
            return(stream.ToArray());
        }
Пример #3
0
        private void Connected()
        {
            connecting        = false;
            connected         = true;
            tcpClient.NoDelay = true;
            ClientMessage message = CreateClientMessage();

            message.playerConnect = new io.gamemachine.messages.PlayerConnect();
            Write(Serialize(message));
        }
Пример #4
0
 public ClientMessage CreateClientMessage()
 {
     io.gamemachine.messages.Player player = new io.gamemachine.messages.Player ();
     player.id = playerId;
     player.authtoken = authtoken;
     ClientMessage clientMessage = new ClientMessage ();
     clientMessage.connection_type = connectionType;
     clientMessage.player = player;
     return clientMessage;
 }
Пример #5
0
 public AsyncUdpClient(string host, int port, string _playerId, int authtoken, bool measure=false)
 {
     playerId = _playerId;
     this.authtoken = authtoken;
     this.host = host;
     this.port = port;
     clientMessage = CreateClientMessage ();
     this.measure = measure;
     receivedPlayerConnected = false;
 }
Пример #6
0
        public ClientMessage CreateClientMessage()
        {
            io.gamemachine.messages.Player player = new io.gamemachine.messages.Player();
            player.id        = playerId;
            player.authtoken = authtoken;
            ClientMessage clientMessage = new ClientMessage();

            clientMessage.connection_type = connectionType;
            clientMessage.player          = player;
            return(clientMessage);
        }
Пример #7
0
        public AsyncTcpClient(string address, int port, string playerId, int authtoken)
            : this(port)
        {
            this.authtoken = authtoken;
            this.playerId = playerId;
            Debug.Log(address);

            if (!IPAddress.TryParse (address, out this.address)) {
                this.address = Dns.GetHostEntry (address).AddressList [0];
            }
            clientMessage = CreateClientMessage ();
        }
Пример #8
0
        public AsyncTcpClient(string address, int port, string playerId, int authtoken)
            : this(port)
        {
            this.authtoken = authtoken;
            this.playerId  = playerId;
            Debug.Log(address);

            if (!IPAddress.TryParse(address, out this.address))
            {
                this.address = Dns.GetHostEntry(address).AddressList [0];
            }
            clientMessage = CreateClientMessage();
        }
Пример #9
0
        public void Stop()
        {
            running = false;
            PlayerLogout logout = new PlayerLogout();

            logout.authtoken = authtoken;
            logout.playerId  = playerId;
            ClientMessage message = CreateClientMessage();

            message.playerLogout = logout;
            byte[] bytes = Serialize(message);
            Write(bytes);
            tcpClient.Close();
        }
Пример #10
0
        private void ReadCallback(IAsyncResult result)
        {
            int           read;
            NetworkStream networkStream;

            try {
                networkStream = tcpClient.GetStream();
                read          = networkStream.EndRead(result);
            } catch {
                Debug.Log("Error reading stream");
                return;
            }

            if (read == 0)
            {
                Debug.Log("Connection closed");
                return;
            }

            // This might look strange but it works well.  We enter here
            // once and then just forever loop on reading the network stream, which
            // blocks until it can read a full protobuf message.  So basically every
            // iteration either has a complete message, or it's blocking, never a busy loop
            ClientMessage clientMessage;

            while (true)
            {
                clientMessage = Deserialize(networkStream);

                if (receivedPlayerConnected)
                {
                    foreach (Entity entity in clientMessage.entity)
                    {
                        ClientMessageQueue.entityQueue.Enqueue(entity);
                    }
                }
                else
                {
                    if (clientMessage.playerConnected != null)
                    {
                        receivedPlayerConnected = true;
                    }
                }
            }

            //byte[] buffer = result.AsyncState as byte[];
            //networkStream.BeginRead (buffer, 0, buffer.Length, ReadCallback, buffer);
        }
Пример #11
0
 private byte[] Serialize(ClientMessage message) {
     MemoryStream stream = new MemoryStream();
     Serializer.Serialize(stream, message);
     return stream.ToArray();
 }
Пример #12
0
 public void Incoming(RpcMessage message) {
     Debug.Log("Incoming");
     ClientMessage clientMessage = new ClientMessage();
     clientMessage.rpcMessage = message;
     ActorSystem.instance.client.Send(Serialize(clientMessage));
 }
Пример #13
0
        public ClientMessage Deserialize(Stream inc)
        {
            ClientMessage clientMessage = Serializer.DeserializeWithLengthPrefix <ClientMessage> (inc, PrefixStyle.Base128);

            return(clientMessage);
        }
Пример #14
0
 private byte[] Serialize(ClientMessage message)
 {
     MemoryStream stream = new MemoryStream ();
     Serializer.SerializeWithLengthPrefix (stream, message, PrefixStyle.Base128);
     return stream.ToArray ();
 }
Пример #15
0
        private void ReadCallback(IAsyncResult result)
        {
            int read;
            NetworkStream networkStream;
            try {
                networkStream = tcpClient.GetStream ();
                read = networkStream.EndRead (result);
            } catch {
                Debug.Log("Error reading stream");
                return;
            }

            if (read == 0) {
                Debug.Log("Connection closed");
                return;
            }

            // This might look strange but it works well.  We enter here
            // once and then just forever loop on reading the network stream, which
            // blocks until it can read a full protobuf message.  So basically every
            // iteration either has a complete message, or it's blocking, never a busy loop
            ClientMessage clientMessage;

            while (true) {

                clientMessage = Deserialize (networkStream);

                if (receivedPlayerConnected) {
                    foreach (Entity entity in clientMessage.entity) {
                        ClientMessageQueue.entityQueue.Enqueue(entity);
                    }
                } else {
                    if (clientMessage.playerConnected != null) {
                        receivedPlayerConnected = true;
                    }
                }
            }

            //byte[] buffer = result.AsyncState as byte[];
            //networkStream.BeginRead (buffer, 0, buffer.Length, ReadCallback, buffer);
        }