コード例 #1
0
 public void AddCommand(NetCommand cmd)
 {
     m_commands.Enqueue(cmd);
 }
コード例 #2
0
        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);
                }
            }
        }