Пример #1
0
 bool NewPlayerJoin(string playerName, TcpClient client)
 {
     try
     {
         if (players.Count > 0)
         {
             if (players.Where(o => o.Value.Name == playerName).Count() > 0)
             {
                 BinaryWriter bw = new BinaryWriter(client.GetStream());
                 bw.Write("Your username has already been taken by another player!");
                 return(false);
             }
         }
         lock (players)
         {
             MpPlayer p = new MpPlayer();
             p.Client   = client;
             p.Position = new Mogre.Vector3();
             players.Add(players.Count, p);
             client.Close();
         }
         ThreadPool.QueueUserWorkItem(PlayerJoinCallback, players.Count);
         return(true);
     }
     catch
     {
         if (client != null)
         {
             client.Close();
         }
         return(false);
     }
 }
Пример #2
0
        public void KickPlayer(int playerId)
        {
            MpPlayer targetPlayer = players.Where(o => o.Key == playerId).FirstOrDefault().Value;

            if (targetPlayer == null)
            {
                return;
            }
            targetPlayer.Client.Close();
        }