예제 #1
0
 public void OnThreadExit(Client c)
 {
     lock (clients)
     {
         if (clients.Contains(c))
         {
             clients.Remove(c);
         }
     }
 }
예제 #2
0
 private void ListenerMain()
 {
     Invoke((Action)delegate { broadcastTimer.Start(); });
     Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     listener.Bind(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5151));
     listener.Listen(10);
     while (true)
     {
         Socket newSock = listener.Accept();
         lock (banlist)
         {
             if (banlist.Any(x => x.Equals(((IPEndPoint)newSock.RemoteEndPoint).Address)))
             {
                 newSock.Close();
                 continue;
             }
         }
         Client c = new Client(this, newSock, log);
         lock (clients)
         {
             clients.Add(c);
         }
         c.Thread.Start();
     }
 }
예제 #3
0
 public void BroadcastMessage(HaProtoImpl.Opcode type, HaProtoImpl.HaProtoPacket packet, Client exempt = null)
 {
     byte[] data = packet.Build();
     lock (clients)
     {
         for (int i = 0; i < clients.Count; i++)
         {
             Client c = clients[i];
             if (c == exempt)
                 continue;
             HaProtoImpl.Send(c.Socket, type, data);
         }
     }
 }