private void OnTxtMsgKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                DateTime now = DateTime.Now;
                string text = "[" + now.Hour.ToString("D2") + ":" + now.Minute.ToString("D2") + ":" + now.Second.ToString("D2") + "] ";
                text += "Game_Master : ";
                text += txtMsg.Text;

                F3_ChatLine newLine = new F3_ChatLine();
                newLine.m_senderUUID = F3_NetCommonConstants.SENDER_GM;
                newLine.m_receiver = this.Text;
                newLine.m_bIsPrivate = true;
                newLine.m_bIsGameMaster = true;
                newLine.m_msg = txtMsg.Text;

                if (m_network.Notify(F3_NetCommonConstants.SENDER_GM, this.Text, txtMsg.Text))
                {
                    m_network.AddMessage(newLine);
                }

                lbChat.Items.Add(text);
                lbChat.TopIndex = lbChat.Items.Count - 1;
                txtMsg.Clear();
            }
        }
        private void OnDisplayShutdownMessage(string message)
        {
            m_network.NotifyEveryone(F3_NetCommonConstants.SENDER_GM, message);

            F3_ChatLine newLine = new F3_ChatLine();
            newLine.m_bIsGameMaster = true;
            newLine.m_senderUUID = F3_NetCommonConstants.SENDER_GM;
            newLine.m_msg = message;
            m_network.AddMessage(newLine);
        }
        private void btnSend_Click(object sender, EventArgs e)
        {
            //send msg to all.
            m_network.NotifyEveryone(F3_NetCommonConstants.SENDER_GM, txtMsg.Text);

            F3_ChatLine newLine = new F3_ChatLine();
            newLine.m_bIsGameMaster = true;
            newLine.m_msg = txtMsg.Text;
            m_network.AddMessage(newLine);

            txtMsg.Clear();
        }
        private void FormatMessage(F3_ChatLine line)
        {
            if (line.m_senderUUID != F3_NetCommonConstants.SENDER_DEBUG &&
                !line.IsPublicAnnouncement())
            {
                string originalMessage = line.m_msg;
                F3_NetPlayerInfo playerInfo = FindPlayerByUUID(line.m_senderUUID);
                line.m_msg = playerInfo.GetPlayerName();

                if (line.m_bIsConnecting || line.m_bIsDisconnecting)
                {
                    line.m_msg += " has " + (line.m_bIsConnecting ? "connected" : "disconnected") + ".";
                    _OnPlayersListDirty();
                    return;
                }

                if (line.m_bIsGroupMsg && line.m_receiver == playerInfo.GetPlayerGuild())
                {
                    line.m_bIsGuildMsg = true;
                }
                else if (line.m_bIsGroupMsg && line.m_receiver.Length == 0)
                {
                    line.m_receiver = playerInfo.GetPlayerDefaultGroup();
                }

                if (line.IsRegularPrivateMsg() || line.m_bIsGroupMsg)
                {
                    line.m_msg += " => " + line.m_receiver;
                }

                if (originalMessage.Length > 0)
                {
                    line.m_msg += ": " + originalMessage;
                }
            }
        }
 public void AddMessage(F3_ChatLine line)
 {
     FormatMessage(line);
     m_messages.Enqueue(line);
 }
        public override void OnStatusChanged(NetIncomingMessage incMsg)
        {
            NetConnectionStatus status = (NetConnectionStatus)incMsg.ReadByte();

            if (status == NetConnectionStatus.Disconnected)
            {
                long uuid = incMsg.SenderConnection.RemoteUniqueIdentifier;
                F3_ChatLine newLine = new F3_ChatLine();
                newLine.m_senderUUID = uuid;
                newLine.m_bIsDisconnecting = true;
                AddMessage(newLine);

                F3_NetPlayerInfo playerInfo = FindPlayerByUUID(uuid);

                if (NotifyGroupOnStatusChangedEnabled() && playerInfo.GetPlayerGuild() != F3_NetCommonConstants.INVALID_GUILD)
                {
                    NotifyGroup(uuid, playerInfo.GetPlayerGuild(), newLine.m_msg, true);
                }

                DisconnectPlayer(uuid);
            }
        }
 public override void OnDebugMessage(NetIncomingMessage incMsg)
 {
     F3_ChatLine newLine = new F3_ChatLine();
     newLine.m_senderUUID = F3_NetCommonConstants.SENDER_DEBUG;
     newLine.m_msg = "NetworkMessage type: " + incMsg.MessageType + " - " + incMsg.ReadString();
     AddMessage(newLine);
 }
        public override void OnDataReceived(NetIncomingMessage incMsg)
        {
            NetDataType type = (NetDataType)incMsg.ReadByte();
            long uuid = incMsg.SenderConnection.RemoteUniqueIdentifier;

            if (type == NetDataType.eDATA_AUTHENTICATION)
            {
                string name = incMsg.ReadString();
                string guild = incMsg.ReadString();
                string defaultgroup = incMsg.ReadString();
                int nbGroups = incMsg.ReadInt32();
                List<string> groups = new List<string>();

                for (int i = 0; i < nbGroups; i++)
                {
                    string group = incMsg.ReadString();
                    groups.Add(group);
                }

                F3_NetPlayerInfo player = new F3_NetPlayerInfo(uuid);
                player.SetPlayerName(name);
                player.SetPlayerGuild(guild);
                player.SetPlayerDefaultGroup(defaultgroup);
                player.SetPlayerPrivateGroups(groups);

                ConnectPlayer(uuid, player);
                AddPlayerToGroups(player);

                F3_ChatLine newLine = new F3_ChatLine();
                newLine.m_senderUUID = uuid;
                newLine.m_bIsConnecting = true;
                AddMessage(newLine);

                if (NotifyGroupOnStatusChangedEnabled() && guild != F3_NetCommonConstants.INVALID_GUILD)
                {
                    NotifyGroup(uuid, guild, newLine.m_msg, true);
                }
            }

            if (type == NetDataType.eDATA_MSG_TO_ALL)
            {
                F3_ChatLine newLine = new F3_ChatLine();
                newLine.m_senderUUID = uuid;
                newLine.m_msg = incMsg.ReadString();

                //Broadcast the message to everyone.
                NotifyEveryone(uuid, newLine.m_msg);

                AddMessage(newLine);
            }

            if (type == NetDataType.eDATA_PRIVATE_MSG)
            {
                F3_ChatLine newLine = new F3_ChatLine();
                newLine.m_senderUUID = uuid;
                newLine.m_receiver = incMsg.ReadString();
                newLine.m_bIsPrivate = true;
                newLine.m_msg = incMsg.ReadString();

                //Broadcast the message to everyone.
                if (Notify(uuid, newLine.m_receiver, newLine.m_msg))
                {
                    AddMessage(newLine);
                }
            }

            if (type == NetDataType.eDATA_GROUP_MSG)
            {

                F3_ChatMessage_Group msg = new F3_ChatMessage_Group();
                msg.FromNetMsg(incMsg);
                F3_ChatLine newLine = new F3_ChatLine();
                newLine.m_senderUUID = uuid;
                newLine.m_receiver = msg.GetGroup();
                newLine.m_bIsGroupMsg = true;
                newLine.m_msg = msg.GetMessage();

                //Broadcast the message to everyone.
                if (NotifyGroup(uuid, newLine.m_receiver, newLine.m_msg, false))
                {
                    AddMessage(newLine);
                }
            }

            if (type == NetDataType.eDATA_EXTERNAL_COMMAND)
            {
                NetCommandIDs cmdId = (NetCommandIDs)incMsg.ReadByte();

                if (cmdId != NetCommandIDs.eCMD_INVALID)
                {
                    NetCommand newCmd = new NetCommand(cmdId);
                    switch (cmdId)
                    {
                        case NetCommandIDs.eCMD_PM_GM:
                            {
                                string text = incMsg.ReadString();

                                F3_ChatLine newLine = new F3_ChatLine();
                                newLine.m_senderUUID = uuid;
                                newLine.m_receiver = "GM";
                                newLine.m_msg = text;
                                newLine.m_bIsPrivate = true;
                                newLine.m_bIsGameMaster = true;

                                AddMessage(newLine);
                                newLine.m_senderUUID = FindPlayerByUUID(uuid).GetPlayerUUID();
                                newCmd.SetUserData(newLine);
                                break;
                            }
                        //case NetCommandIDs.eCMD_SHUTDOWN:   //No User Data for now. Could add NetworkShutdownSequence perhaps.

                        default:
                            {
                                Console.WriteLine("Unrecognized Command");
                                break;
                            }
                    }

                    AddCommand(newCmd);
                }
            }
        }