private static void OnServerChatRecieved(Helpers.TcpServerChat tcpServerChat)
        {
            if (chatMessages.Count == 18)
            {
                chatMessages.RemoveAt(0);
            }
            string color = "";

            switch ((Helpers.TcpServerChatType)tcpServerChat.Data.GetValue("type"))
            {
            case Helpers.TcpServerChatType.Error:
                color = "red";
                break;

            case Helpers.TcpServerChatType.Info:
                color = "blue";
                break;

            case Helpers.TcpServerChatType.Warn:
                color = "orange";
                break;
            }
            chatMessages.Add($"<color={color}>{(string)tcpServerChat.Data.GetValue("message")}</color>");
            chatLogMessages.Add($"[Server] [{DateTime.Now.ToString()}] [{Enum.GetName(typeof(Helpers.TcpServerChatType), (Helpers.TcpServerChatType)tcpServerChat.Data.GetValue("type"))}] {(string)tcpServerChat.Data.GetValue("message")}");
            chatWindow.text = string.Join("\n", chatMessages);
        }
 public static void Send(Helpers.TcpServerChat tcpServerChat)
 {
     Logging.Info("[Server] Sending server wide message: " + (string)tcpServerChat.Data.GetValue("message"));
     foreach (Helpers.User user in Users)
     {
         server.Send(user.ID, tcpServerChat.Serialize());
     }
 }
示例#3
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);
            }
        }