Example #1
0
        public static void ChatMessage(Client pClient, Packet pPacket)
        {
            string message;
            pPacket.ReadString (out message);

            Log.WriteLine (ELogLevel.Info, "[Server] Received Chat Message: {0}", message);

            Packet packet = new Packet(EOpcode.SMSG_CHAT_MESSAGE);
            packet.WriteString (pClient.Username);
            packet.WriteString(message);
            Server.SendPacketToAllExcept (packet, pClient);
        }
Example #2
0
        private static void ConnectCallback(IAsyncResult ar)
        {
            try {
                sServerSocket.EndConnect (ar);
                Log.WriteLine(ELogLevel.Info, "[Client] Connected to Server");

                sServer = new Server(sServerSocket);

                Packet p = new Packet(EOpcode.CMSG_CHAT_MESSAGE);
                p.WriteString("Hello");
                sServer.SendPacket(p);

            } catch (Exception e) {
                sRetryCount++;
                Log.WriteLine(ELogLevel.Info, "[Client] Could not connect to server: {0}", e.Message);

                if (sRetryCount < 3) {
                    Log.WriteLine (ELogLevel.Info, "[Client] Reattempting to connect to server");
                    Thread.Sleep (1000);
                    sServerSocket.BeginConnect ("localhost", 8484, new AsyncCallback (ConnectCallback), null);
                } else {
                    Log.WriteLine (ELogLevel.Error, "[Client] Cannot connect to server");
                }
            }
        }
Example #3
0
 public static void SendMessage(string pMessage)
 {
     Packet packet = new Packet (EOpcode.CMSG_CHAT_MESSAGE);
     packet.WriteString (pMessage);
     sServer.SendPacket (packet);
 }
Example #4
0
 internal static void updateUsername(string pUsername)
 {
     Packet packet = new Packet (EOpcode.CMSG_UPDATE_USERNAME);
     packet.WriteString (pUsername);
     sServer.SendPacket (packet);
 }
Example #5
0
 internal static void SendWelcomeMessage(Client pClient)
 {
     Packet packet = new Packet(EOpcode.SMSG_WELCOME_MESSAGE);
     packet.WriteString (Config.Instance.WelcomeMessage);
     pClient.SendPacket (packet);
 }
Example #6
0
        internal static void UpdateUsername(Client pClient, string pUsername)
        {
            bool success = true;
            if (sClients.Any (c => c.Username.Equals (pUsername, StringComparison.CurrentCulture))) {
                success = false;
            }

            Packet packet = new Packet(EOpcode.SMSG_UPDATE_USERNAME);
            packet.WriteBool (success);

            if (success) {
                packet.WriteString (pUsername);
                pClient.Username = pUsername;
            }

            Log.WriteLine (ELogLevel.Info, "Sending Uusername: {0}", pUsername);

            pClient.SendPacket (packet);
        }