public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            NewOnlinePlayer = new OnlinePlayer(Buffer, cursor);
            cursor += NewOnlinePlayer.ByteLength;

            return cursor - StartIndex;
        }
示例#2
0
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            ushort len = BitConverter.ToUInt16(Buffer, cursor);
            cursor += TypeSizes.SHORT;

            OnlinePlayers = new OnlinePlayer[len];
            for (int i = 0; i < len; i++)
            {
                OnlinePlayers[i] = new OnlinePlayer(Buffer, cursor);
                cursor += OnlinePlayers[i].ByteLength;
            }

            return cursor - StartIndex;
        }
示例#3
0
        public override unsafe void ReadFrom(ref byte* Buffer)
        {
            base.ReadFrom(ref Buffer);

            ushort len = *((ushort*)Buffer);
            Buffer += TypeSizes.SHORT;

            OnlinePlayers = new OnlinePlayer[len];
            for (int i = 0; i < len; i++)           
                OnlinePlayers[i] = new OnlinePlayer(ref Buffer);
            
        }
示例#4
0
 public PlayersMessage(OnlinePlayer[] OnlinePlayers) 
     : base(MessageTypeGameMode.Players)
 {
     this.OnlinePlayers = OnlinePlayers;
 }
示例#5
0
        /// <summary>
        /// Almost exactly like ParseGoPlayer
        /// </summary>
        /// <param name="Words"></param>
        /// <param name="Text"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        protected static ChatCommandGetPlayer ParseGetPlayer(string[] Words, string Text, DataController Data)
        {
            Tuple <int, int, string> quote   = null;
            ChatCommandGetPlayer     command = null;
            OnlinePlayer             player  = null;
            string prefix            = null;
            List <OnlinePlayer> list = null;
            int num = 0;

            if (Words == null || Words.Length < 2)
            {
                return(null);
            }

            // extract quoted name if second word starts with "
            // this is necessary to not care about quoted text (t someone "yes yes")
            // but only for quoted names (t "mister x" hello!)
            if (Words[1].Length > 0 && Words[1][0] == QUOTECHAR)
            {
                quote = Text.GetQuote();
            }

            /********* QUOTED NAME *********/
            if (quote != null)
            {
                // try get exact match for quoted name
                player = Data.OnlinePlayers.GetItemByName(quote.Item3);

                if (player != null)
                {
                    command = new ChatCommandGetPlayer(player.ID);
                }

                // no player with that name
                else
                {
                    Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                              "No player with name: " + quote.Item3));
                }
            }

            /********* UNQUOTED NAME *********/
            else
            {
                prefix = Words[1];
                list   = Data.OnlinePlayers.GetItemsByNamePrefix(prefix);

                // extend prefix with more words
                // until there is only one or zero matches found
                // or until there is only one more word left (supposed minimal text)
                num = 2;
                while (list.Count > 1 && num < Words.Length)
                {
                    prefix += DELIMITER + Words[num];
                    list    = Data.OnlinePlayers.GetItemsByNamePrefix(prefix);
                    num++;
                }

                if (list.Count == 1)
                {
                    command = new ChatCommandGetPlayer(list[0].ID);
                }

                // still more than one player with max. prefix
                else if (list.Count > 1)
                {
                    Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                              "More than one player with prefix: " + prefix));
                }

                // no player with that prefix
                else
                {
                    Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                              "No player with prefix: " + prefix));
                }
            }

            return(command);
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Words"></param>
        /// <param name="Text"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        protected static ChatCommandTell ParseTell(string[] Words, string Text, DataController Data)
        {
            Tuple <int, int, string> quote   = null;
            ChatCommandTell          command = null;
            OnlinePlayer             player  = null;
            Group  group                   = null;
            string prefix                  = null;
            List <OnlinePlayer> list       = null;
            List <Group>        listGroups = null;
            int num = 0;
            int sum = 0;

            if (Words == null || Words.Length < 2)
            {
                return(null);
            }

            // extract quoted name if second word starts with "
            // this is necessary to not care about quoted text (t someone "yes yes")
            // but only for quoted names (t "mister x" hello!)
            if (Words[1].Length > 0 && Words[1][0] == QUOTECHAR)
            {
                quote = Text.GetQuote();
            }

            /********* QUOTED NAME *********/
            if (quote != null)
            {
                // try get exact player and group match for quoted name
                player = Data.OnlinePlayers.GetItemByName(quote.Item3);
                group  = Data.Groups.GetItemByName(quote.Item3);

                // player or group match
                if (group != null || player != null)
                {
                    // startindex of actual text
                    int idx = Words[0].Length + quote.Item2 + 2;

                    // correct tell
                    if (idx < Text.Length)
                    {
                        string sendtext = Text.Substring(idx, Text.Length - idx);

                        // prefer group match
                        if (group != null)
                        {
                            // collect ids from online-player list
                            List <uint> ids = new List <uint>();
                            foreach (GroupMember m in group.Members)
                            {
                                OnlinePlayer p = Data.OnlinePlayers.GetItemByName(m.Name);

                                if (p != null)
                                {
                                    ids.Add(p.ID);
                                }
                            }

                            // at least one person is online
                            if (ids.Count > 0)
                            {
                                command = new ChatCommandTell(ids.ToArray(), sendtext);
                            }

                            // no one of the group is online
                            else
                            {
                                Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                                          "No member of the group " + group.Name + " is online."));
                            }
                        }

                        // player match
                        else if (player != null)
                        {
                            command = new ChatCommandTell(player.ID, sendtext);
                        }
                    }

                    // empty text
                    else
                    {
                        Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                                  "Can't send empty message."));
                    }
                }

                // no player or group with that name
                else
                {
                    Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                              "No player or group with name: " + quote.Item3));
                }
            }

            /********* UNQUOTED NAME *********/
            else
            {
                prefix     = Words[1];
                list       = Data.OnlinePlayers.GetItemsByNamePrefix(prefix);
                listGroups = Data.Groups.GetItemsByNamePrefix(prefix);

                // extend prefix with more words
                // until there is only one or zero matches found
                // or until there is only one more word left (supposed minimal text)
                num = 2;
                sum = list.Count + listGroups.Count;
                while (sum > 1 && num < Words.Length - 1)
                {
                    prefix    += DELIMITER + Words[num];
                    list       = Data.OnlinePlayers.GetItemsByNamePrefix(prefix);
                    listGroups = Data.Groups.GetItemsByNamePrefix(prefix);
                    sum        = list.Count + listGroups.Count;
                    num++;
                }

                if (sum == 1)
                {
                    // startindex of actual text
                    int idx = Words[0].Length + prefix.Length + 2;

                    if (idx < Text.Length)
                    {
                        string sendtext = Text.Substring(idx, Text.Length - idx);

                        // to player
                        if (list.Count == 1)
                        {
                            command = new ChatCommandTell(list[0].ID, sendtext);
                        }

                        // to group
                        else if (listGroups.Count == 1)
                        {
                            // collect ids from online-player list
                            List <uint> ids = new List <uint>();
                            foreach (GroupMember m in listGroups[0].Members)
                            {
                                OnlinePlayer p = Data.OnlinePlayers.GetItemByName(m.Name);

                                if (p != null)
                                {
                                    ids.Add(p.ID);
                                }
                            }

                            // at least one person is online
                            if (ids.Count > 0)
                            {
                                command = new ChatCommandTell(ids.ToArray(), sendtext);
                            }

                            // no one of the group is online
                            else
                            {
                                Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                                          "No member of the group " + listGroups[0].Name + " is online."));
                            }
                        }
                    }
                    else
                    {
                        // empty text
                        Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                                  "Can't send empty message."));
                    }
                }

                // still more than one player or group with max. prefix
                else if (sum > 1)
                {
                    Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                              "More than one player or group with prefix: " + prefix));
                }

                // no player or group with that prefix
                else
                {
                    Data.ChatMessages.Add(ServerString.GetServerStringForString(
                                              "No player or group with prefix: " + prefix));
                }
            }

            return(command);
        }
 public PlayerAddMessage(OnlinePlayer onlinePlayer) 
     : base(MessageTypeGameMode.PlayerAdd)
 {         
     this.NewOnlinePlayer = onlinePlayer;
 }
 public override unsafe void ReadFrom(ref byte* Buffer)
 {
     base.ReadFrom(ref Buffer);
     NewOnlinePlayer = new OnlinePlayer(ref Buffer);
 }