Example #1
0
 /// <summary>
 /// Constructor of this class
 /// </summary>
 /// <param name="requestedNick">Requested initial nick</param>
 public NetworkClient(string requestedNick)
 {
   Stopping = false;
   serverMessages = new Queue<string[]>();
   localData = new ClientData() { Name = requestedNick };
   users = new List<ClientData>();
 }
Example #2
0
 /// <summary>
 /// Parse received userlist
 /// </summary>
 /// <param name="lineParts">Network message</param>
 private void UserList(string[] lineParts)
 {
   int i = 1;
   // If the list is empty, build it from the provided data
   if (users.Count == 0)
   {
     while (i < lineParts.Length)
     {
       ClientData data = new ClientData();
       data.Deserialize(MessageType.UserList, lineParts, ref i, null);
       users.Add(data);
       // If current user is this (local client) player, use these data
       if (data.Name == localData.Name)
       {
         this.localData = data;
       }
     }
   }
   // If the list isn't empty, validate & update all entries
   else
   {
     // Reset validation indicator
     foreach (var data in users)
       data.Valid = false;
     while (i < lineParts.Length)
     {
       string uName = lineParts[i];
       bool found = false;
       // Try to find the user first
       foreach (var data in users)
         if (data.Name == uName)
         {
           found = true;
           data.Valid = true;
           data.Deserialize(MessageType.UserList, lineParts, ref i, null);
           break;
         }
       // Add new user
       if (!found)
       {
         ClientData data = new ClientData();
         data.Deserialize(MessageType.UserList, lineParts, ref i, null);
         users.Add(data);
         Network.AddMessage(data.Name + " connected");
       }
     }
     // Remove nonexistent users
     foreach (var data in new List<ClientData>(users))
       if (!data.Valid)
       {
         Network.AddMessage(data.Name + " disconnected");
         users.Remove(data);
       }
   }
 }