Esempio n. 1
0
        static void OnServerResponse(Helpers.TcpResponse response)
        {
            object type = response.Data.GetValue("type");

            if (type == null)
            {
                Logging.Warn("[Client] Type is null!");
                return;
            }
            if ((string)type == "login_request")
            {
                Send(new Helpers.TcpLogin(Username, ServerPassword));
            }
            else if ((string)type == "login_response")
            {
                string res = (string)response.Data.GetValue("data");
                if (res == "ok")
                {
                    //Login ok
                    Logging.Info("[Client] You're logged in now!");
                    //Send request to get GameWorld
                    Send(new Helpers.TcpRequest("gameworld"));
                }
                else if (res == "max_players")
                {
                    //Server full
                    Logging.Warn("[Client] The server is full");
                }
                else if (res == "wrong_password")
                {
                    //Wrong password
                    Logging.Warn("[Client] You did enter the wrong password");
                }
            }
        }
Esempio n. 2
0
        static void Receive(byte[] data)
        {
            Logging.Info("[Client] Data from Server: " + data.Length + " bytes");

            //Handle TcpResponse
            Helpers.TcpResponse tcpresponse = Helpers.TcpResponse.Deserialize(data);
            if (tcpresponse != null && tcpresponse.Header == "response")
            {
                OnServerResponse(tcpresponse);
            }

            //Handle TcpServerChat
            Helpers.TcpServerChat tcpServerChat = Helpers.TcpServerChat.Deserialize(data);
            if (tcpServerChat != null && tcpServerChat.Header == "serverchat")
            {
                OnServerChatRecieved(tcpServerChat);
            }

            //Handle TcpChat
            Helpers.TcpChat tcpchat = Helpers.TcpChat.Deserialize(data);
            if (tcpchat != null && tcpchat.Header == "chat")
            {
                OnChatReceived(tcpchat);
            }

            //Handle GameWorld
            Helpers.TcpGameWorld tcpworld = Helpers.TcpGameWorld.Deserialize(data);
            if (tcpworld != null && tcpworld.Header == "gameworld")
            {
                OnGameWorldReceived(tcpworld);
            }

            //Handle Gamespeed
            Helpers.TcpGamespeed tcpspeed = Helpers.TcpGamespeed.Deserialize(data);
            if (tcpspeed != null && tcpspeed.Header == "gamespeed")
            {
                OnGamespeedChange(tcpspeed);
            }
        }
 public static void Send(int clientid, Helpers.TcpResponse response)
 {
     Logging.Info("[Server] Sending response to client " + clientid);
     //server.Send(clientid, response.ToArray());
     server.Send(clientid, response.Serialize());
 }
Esempio n. 4
0
 public static void Send(Helpers.TcpResponse response)
 {
     Logging.Info("[Client] Sending response");
     client.Send(response.Serialize());
 }