예제 #1
0
        private void HandleMessage(Packet02Message messagePacket)
        {
            gameForm.Chat_textBox.Text += messagePacket.GetUsername() + " : " + messagePacket.GetMessage() + Environment.NewLine;
            int caretPos = gameForm.Chat_textBox.Text.Length;

            gameForm.Chat_textBox.Select(caretPos, 0);
            gameForm.Chat_textBox.ScrollToCaret();
        }
예제 #2
0
        public void ParsePacket(byte[] data, String ipAddress)
        {
            String dataStr = System.Text.ASCIIEncoding.UTF8.GetString(data).Trim();

            Packet.PacketTypes type   = Packet.FindPacket(dataStr.Substring(0, 2));
            PlayerMP           player = null;

            switch (type)
            {
            case Packet.PacketTypes.INVALID:
                break;

            case Packet.PacketTypes.LOGIN:
                Packet00Login loginPacket = new Packet00Login(data);
                player = new PlayerMP(loginPacket.GetUsername(), ipAddress, int.Parse(loginPacket.GetPort()), 0);
                AddConnection(player, loginPacket);
                break;

            case Packet.PacketTypes.DISCONNECT:
                Packet01Disconnect disconnectPacket = new Packet01Disconnect(data);
                RemoveConnection(disconnectPacket);
                break;

            case Packet.PacketTypes.MESSAGE:
                Packet02Message messagePacket = new Packet02Message(data);
                player = GetPlayerMPNode(messagePacket.GetUsername());

                // Only send message to the players that are in the same room
                foreach (PlayerMP p in connectedPlayers)
                {
                    if (!p.username.Equals(player.username) && p.roomNumber.Equals(player.roomNumber))
                    {
                        SendData(data, p.ipAddress, p.port);
                    }
                }
                break;

            case Packet.PacketTypes.ROUND_START:
                SendDataToAllClientsNotServer(data);
                break;

            case Packet.PacketTypes.ROUND_END:
                Packet04RoundEnd roundEndPacket = new Packet04RoundEnd(data);
                player = GetPlayerMPNode(roundEndPacket.GetUsername());
                //player.roomNumber = Room.GetRoomIndex(roundEndPacket.GetDestination());
                //Room.Effect(ref player);
                SendData(data, player.ipAddress, player.port);
                break;
            }
        }
예제 #3
0
        private void ChatSend_textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                String message = ChatSend_textBox.Text;
                if (message.Length > 0)
                {
                    Packet02Message messagePacket = new Packet02Message(Form1.GetPlayerMP().username, message.Trim());
                    messagePacket.WriteData(Form1.GetGameClient());

                    ChatSend_textBox.Clear();

                    Chat_textBox.Text += messagePacket.GetUsername() + " : " + messagePacket.GetMessage() + Environment.NewLine;
                    int caretPos = Chat_textBox.Text.Length;
                    Chat_textBox.Select(caretPos, 0);
                    Chat_textBox.ScrollToCaret();
                }
            }
        }