Пример #1
0
 /// <summary>
 /// Client connection accepted event
 /// </summary>
 /// <param name="serverConnection">Server connection</param>
 private void ClientConnectionAcceptedEvent(ServerConnection serverConnection)
 {
     lock (users)
     {
         int user_id = users.NextAvailableID;
         if (user_id == users.InvalidID)
         {
             serverListener.Disconnect(serverConnection);
         }
         else
         {
             ServerUser user = new ServerUser(user_id, "Unknown", serverConnection);
             users.Add(user);
             serverConnection.SendPlayerNumberMessageAsync(user);
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Send game chat message
 /// </summary>
 /// <param name="targetUser">Target user</param>
 /// <param name="message">Message</param>
 public void SendGameChatMessage(IUser targetUser, string message)
 {
     if ((targetUser != null) && (message != null))
     {
         string trimmed_message = message.Trim();
         if (trimmed_message.Length > 0)
         {
             lock (users)
             {
                 if (users.IsIDValid(targetUser.ID))
                 {
                     ServerUser target_user = targetUser as ServerUser;
                     if (target_user != null)
                     {
                         target_user.ServerConnection.SendGameChatMessageMessageAsync(trimmed_message);
                     }
                 }
             }
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Send game chat message
 /// </summary>
 /// <param name="senderUser">Sender user</param>
 /// <param name="targetUser">Target user</param>
 /// <param name="message">Message</param>
 public void SendGameChatMessageToAll(IUser senderUser, IUser targetUser, string message)
 {
     if ((senderUser != null) && (targetUser != null) && (message != null))
     {
         string trimmed_message = message.Trim();
         if (trimmed_message.Length > 0)
         {
             lock (users)
             {
                 if (IsRealUser(senderUser) && users.IsIDValid(targetUser.ID))
                 {
                     IUser      sender_user = GetRealUser(senderUser);
                     ServerUser target_user = users[targetUser.ID] as ServerUser;
                     if (target_user != null)
                     {
                         target_user.ServerConnection.SendGameChatMessageMessageAsync(sender_user, trimmed_message);
                     }
                 }
             }
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Send chat action
 /// </summary>
 /// <param name="senderUser">Sender user</param>
 /// <param name="targetUser">Target user</param>
 /// <param name="action">Action</param>
 public void SendChatAction(IUser senderUser, IUser targetUser, string action)
 {
     if ((senderUser != null) && (targetUser != null) && (action != null))
     {
         string trimmed_action = action.Trim();
         if (trimmed_action.Length > 0)
         {
             lock (users)
             {
                 if (IsRealUser(senderUser) && users.IsIDValid(targetUser.ID))
                 {
                     IUser      sender_user = GetRealUser(senderUser);
                     ServerUser target_user = users[targetUser.ID] as ServerUser;
                     if (target_user != null)
                     {
                         target_user.ServerConnection.SendChatActionMessageAsync(sender_user, trimmed_action);
                     }
                 }
             }
         }
     }
 }