コード例 #1
0
        /// <summary>
        /// Gets called whenever a message (other than connect or disconnect) gets received
        /// </summary>
        /// <param name="msg">The Telepathy.Message sent by the server.getNextMessage() function</param>
        static void Receive(Telepathy.Message msg)
        {
            //string datastr = Encoding.UTF8.GetString(msg.data);
            //Logging.Info($"[Server] From Connection {msg.connectionId}: " + datastr);
            Logging.Info($"[Server] Data from Connection {msg.connectionId}: {msg.data.Length} bytes");

            //Handle TCPLogin
            //Helpers.TcpLogin tcplogin = XML.From<Helpers.TcpLogin>(datastr);
            Helpers.TcpLogin tcplogin = Helpers.TcpLogin.Deserialize(msg.data);
            if (tcplogin != null && tcplogin.Header == "login")
            {
                OnUserLogin(msg.connectionId, tcplogin);
            }

            //Handle TCPChat
            //Helpers.TcpChat tcpchat = XML.From<Helpers.TcpChat>(datastr);
            Helpers.TcpChat tcpchat = Helpers.TcpChat.Deserialize(msg.data);
            if (tcpchat != null && tcpchat.Header == "chat")
            {
                OnUserChat(msg.connectionId, tcpchat);
            }

            //Handle TCPRequests
            //Helpers.TcpRequest tcprequest = XML.From<Helpers.TcpRequest>(datastr);
            Helpers.TcpRequest tcprequest = Helpers.TcpRequest.Deserialize(msg.data);
            if (tcprequest != null && tcprequest.Header == "request")
            {
                string req = (string)tcprequest.Data.GetValue("request");
                if (req == "gameworld")
                {
                    OnRequestGameWorld(msg.connectionId);
                }
                else if (req == "userlist")
                {
                    OnRequestUserList(msg.connectionId);
                }
            }

            Helpers.TcpGamespeed tcpspeed = Helpers.TcpGamespeed.Deserialize(msg.data);
            if (tcpspeed != null && tcpspeed.Header == "gamespeed")
            {
                OnGamespeedChange(msg.connectionId, tcpspeed);
            }
        }
コード例 #2
0
 public static void Send(int clientid, Helpers.TcpRequest request)
 {
     Logging.Info("[Server] Sending request to client " + clientid);
     //server.Send(clientid, request.ToArray());
     server.Send(clientid, request.Serialize());
 }
コード例 #3
0
 public static void Send(Helpers.TcpRequest request)
 {
     Logging.Info("[Client] Sending request");
     client.Send(request.Serialize());
 }