Beispiel #1
0
        /// <summary>
        /// Adds message to the queue of chatroom messages.
        /// Also sends the message to chatroom membes.
        /// </summary>
        /// <param name="sender">Client, who sent the message.</param>
        /// <param name="message">Text message.</param>
        public void PushMessage(ConnectedClient sender, String message)
        {
            // Checks if message is actual game command.
            if (message.StartsWith("/giveall "))
            {
                if (sender.AccData.Group == UserGroup.ADMINISTRATOR)
                {
                    String[] commandParts = message.Split(new Char[] { ' ' }, 2);
                    if (commandParts.Length > 1)
                    {
                        ConnectedClient foundCli = this.gameServer.FindClient(commandParts[1]);
                        if (foundCli == null)
                        {
                            sender.SendMessage(String.Format("systemChat`User '{0}' is not currently online.", commandParts[1]));
                        }
                        else
                        {
                            foundCli.AccData.HatSeq             = BodyParts.PARTS_ALL_HATS;
                            foundCli.AccData.HeadSeq            = BodyParts.PARTS_ALL_HEADS;
                            foundCli.AccData.BodySeq            = BodyParts.PARTS_ALL_BODIES;
                            foundCli.AccData.FeetSeq            = BodyParts.PARTS_ALL_FEET;
                            foundCli.AccData.HatSeqEpic         = BodyParts.PARTS_ALL_HATS;
                            foundCli.AccData.HeadSeqEpic        = BodyParts.PARTS_ALL_HEADS;
                            foundCli.AccData.BodySeqEpic        = BodyParts.PARTS_ALL_BODIES;
                            foundCli.AccData.FeetSeqEpic        = BodyParts.PARTS_ALL_FEET;
                            foundCli.AccData.ObtainedRankTokens = 150;

                            sender.SendMessage(String.Format("systemChat`Success! User '{0}' has unlocked everything.", commandParts[1]));
                        }

                        return;
                    }
                }
            }

            String niceMessage = String.Format("chat`{0}`{1}`{2}", sender.AccData.Username, sender.AccData.Group, message);

            lock (this.messagesSyncLock)
            {
                this.messages.Enqueue(niceMessage);
                if (this.messages.Count > 20)
                {
                    this.messages.Dequeue();
                }
            }

            lock (this.membersSyncLock)
            {
                foreach (ConnectedClient cli in this.members.Values)
                {
                    cli.SendMessage(niceMessage);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sends info about all slots in this occupancy info (level) to the client.
        /// </summary>
        /// <param name="client">Client who will receive info about slots.</param>
        public void SendMeSlotsStatus(ConnectedClient client)
        {
            lock (this.slotsSyncLock)
            {
                foreach (SlotInfo slot in this.slots)
                {
                    client.SendMessage(String.Format("fillSlot{0}`{1}`{2}`{3}", this.LevelIdentifier, slot.Slot, slot.Client.AccData.Username, slot.Client.AccData.Rank));

                    if (slot.Confirmed)
                    {
                        client.SendMessage(String.Format("confirmSlot{0}`{1}", this.LevelIdentifier, slot.Slot));
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// RPC handler when client is successfuly authentificated on the web server.
        /// Sends login successful packet which will display lobby on the client.
        /// </summary>
        /// <param name="loginId">Login id sent by web server.</param>
        /// <param name="accModel">Accoutn model sent by web server.</param>
        public void LoginSuccessful(Int32 loginId, AccountDataDTO accData)
        {
            ConnectedClient cli = null;

            lock (this.clientsNotAuthSyncLock)
            {
                // Try to find connected client with specific login id.

                this.clientsNotAuth.TryGetValue(loginId, out cli);
            }

            if (cli == null)
            {
                // Client not found.

                Console.WriteLine("Error occured while attempting to authentificate client {0}.", loginId);
            }
            else
            {
                // Client found. Do the authentification procedure.

                lock (this.clientsNotAuthSyncLock)
                {
                    this.clientsNotAuth.Remove(loginId);
                }

                lock (this.clientsAuthSyncLock)
                {
                    this.clientsAuth.Add(loginId, cli);
                }

                cli.IsAuthentificated = true;
                cli.AccData           = accData;

                cli.SendMessage("loginSuccessful`1");
                cli.SendMessage(String.Format("setRank`{0}", cli.AccData.Rank));
                if (cli.AccData.Group > UserGroup.MEMBER)
                {
                    cli.SendMessage(String.Format("setGroup`{0}", cli.AccData.Group));
                }
                //cli.SendMessage("message`Welcome to PR2 private server. :)");
            }
        }
Beispiel #4
0
 /// <summary>
 /// Sends all messages of the currrent chatroom to specified client. Useful, when client connects to chatroom.
 /// </summary>
 /// <param name="receiver">Client, who will receive the messages.</param>
 public void SendMeMessages(ConnectedClient receiver)
 {
     lock (this.messagesSyncLock)
     {
         foreach (String msg in this.messages)
         {
             receiver.SendMessage(msg);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Sends list of players online to the client.
        /// </summary>
        /// <param name="client">Receiver of the list.</param>
        public void SendOnlineList(ConnectedClient destClient)
        {
            // TODO - Implement better solution rather than iteration on every request.

            lock (this.clientsAuthSyncLock)
            {
                foreach (ConnectedClient cli in this.clientsAuth.Values)
                {
                    destClient.SendMessage(String.Format("addUser`{0}`{1}`{2}`{3}", cli.AccData.Username, cli.AccData.Group, cli.AccData.Rank, cli.AccData.HatSeq.Split(Separators.COMMA_SEPARATOR, StringSplitOptions.RemoveEmptyEntries).Length - 1));
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// This method firstly sends message to player who filled the slot so that it succeeded.
        /// Next up, remaining members of this room will be notified that this slot has been filled.
        /// </summary>
        /// <param name="sender">Client who filled the specified slot.</param>
        /// <param name="identifier">Occupancy info (level) identifier in levelID_version format.</param>
        /// <param name="slot">Slot number.</param>
        private void broadcastFillSlot(ConnectedClient sender, String identifier, Int32 slot)
        {
            // First off notify the sender that he successfuly filled slot.
            sender.SendMessage(String.Format("fillSlot{0}`{1}`{2}`{3}`me", identifier, slot, sender.AccData.Username, sender.AccData.Rank));

            // Next up notify other members of this room that the slot has been filled.
            lock (this.membersSyncLock)
            {
                // TODO - Use LINQ?
                foreach (Int32 clientLID in this.members.Keys)
                {
                    if (sender.LoginID != clientLID)
                    {
                        this.members[clientLID].SendMessage(String.Format("fillSlot{0}`{1}`{2}`{3}", identifier, slot, sender.AccData.Username, sender.AccData.Rank));
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Sends list of chat rooms to the specific client.
        /// </summary>
        /// <param name="client">Receiver of the chat rooms list.</param>
        public void SendMeChatRoomList(ConnectedClient client)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append("setChatRoomList");

            lock (this.chatRoomsSyncLock)
            {
                foreach (ChatRoom room in this.chatRooms.Values)
                {
                    strBuilder.Append(Separators.ARG_SEPARATOR);
                    strBuilder.Append(room.Name);
                    strBuilder.Append(" - ");
                    strBuilder.Append(room.MembersCount);
                }
            }

            client.SendMessage(strBuilder.ToString());
        }
Beispiel #8
0
        /// <summary>
        /// RPC handler. Adds system message to chat room main.
        /// </summary>
        /// <param name="message">Message content.</param>
        /// <param name="user">If specified, only this user will see the system message.</param>
        public void SystemMessage(String message, String user)
        {
            if (String.IsNullOrEmpty(message))
            {
                return;
            }

            if (user == null)
            {
                if (this.chatRooms[GameRooms.ROOM_MAIN] != null)
                {
                    this.chatRooms[GameRooms.ROOM_MAIN].PushSystemMessage(message);
                }
            }
            else
            {
                ConnectedClient foundClient = this.FindClient(user);
                if (foundClient != null)
                {
                    foundClient.SendMessage(String.Concat("systemChat`", message));
                }
            }
        }