Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Feb 26th, 2012  |  syntax: C#  |  size: 2.37 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int totalQueuedPackets = 0;
  2.             foreach (RemoteClient c in Clients)
  3.                 totalQueuedPackets += c.PacketQueue.Count;
  4.             // Any leftover time from each client is given to any client that could use it
  5.             double additionalTime = 0;
  6.  
  7.             foreach (RemoteClient c in Clients)
  8.             {
  9.                 if (!c.TcpClient.Connected)
  10.                 {
  11.                     if (OnPlayerConnectionChanged != null && c.LoggedIn)
  12.                         OnPlayerConnectionChanged(this, new PlayerConnectionEventArgs(ConnectionState.Disconnected, c));
  13.                     // Despawn
  14.                 }
  15.                 else
  16.                 {
  17.                     newClientList.Add(c);
  18.                     try
  19.                     {
  20.                         // Read in a packet
  21.                         Packet p = Packet.GetPacket((PacketID)c.TcpClient.GetStream().ReadByte(), true);
  22.                         p.ReadPacket(c);
  23.                         p.HandlePacket(this, c);
  24.                         // Write out from the packet queue
  25.                         // For the sake of server speed, each client is limited in the amount
  26.                         // of time per tick they are allocated for sending of packets.
  27.                         DateTime startTime = DateTime.Now;
  28.                         double maxClientSendTime = (1 / 20) * (c.PacketQueue.Count / totalQueuedPackets) + additionalTime;
  29.                         additionalTime = 0;
  30.                         while (c.PacketQueue.Count != 0 && (DateTime.Now - startTime).TotalMilliseconds <= maxClientSendTime)
  31.                         {
  32.  
  33.                         }
  34.                         if ((DateTime.Now - startTime).TotalMilliseconds <= maxClientSendTime)
  35.                         {
  36.                             additionalTime += maxClientSendTime - (DateTime.Now - startTime).TotalMilliseconds;
  37.                         }
  38.                     }
  39.                     catch
  40.                     {
  41.                         if (OnPlayerConnectionChanged != null && c.LoggedIn)
  42.                             OnPlayerConnectionChanged(this, new PlayerConnectionEventArgs(ConnectionState.Disconnected, c));
  43.                         // Despawn
  44.                         newClientList.RemoveAt(newClientList.Count - 1);
  45.                     }
  46.                 }
  47.             }
  48.  
  49.             Clients = newClientList;