public override void run()
        {
            try
            {
                if (_client == null)
                {
                    return;
                }
                Account p = _client._player;
                Room    r = p == null ? null : p._room;
                if (r != null)
                {
                    if (r._state != RoomState.Ready || r._leader == p._slotId)
                    {
                        return;
                    }
                    List <Account> players = r.getAllPlayers();
                    if (players.Count == 0)
                    {
                        return;
                    }

                    if ((int)p.access >= 4)
                    {
                        ChangeLeader(r, players, p._slotId);
                    }
                    else
                    {
                        if (!r.requestHost.Contains(p.player_id))
                        {
                            r.requestHost.Add(p.player_id);
                            if (r.requestHost.Count() < (players.Count / 2) + 1)
                            {
                                using (ROOM_GET_HOST_PAK packet = new ROOM_GET_HOST_PAK(p._slotId))
                                    SendPacketToRoom(packet, players);
                            }
                        }
                        if (r.requestHost.Count() >= (players.Count / 2) + 1)
                        {
                            ChangeLeader(r, players, p._slotId);
                        }
                    }
                }
                else
                {
                    _client.SendPacket(new ROOM_GET_HOST_PAK(0x80000000));
                }
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[ROOM_REQUEST_HOST_REC.run] Erro fatal!");
            }
        }
Beispiel #2
0
 public override void run()
 {
     try
     {
         if (this._client == null)
         {
             return;
         }
         Account player = this._client._player;
         Room    r      = player == null ? (Room)null : player._room;
         if (r != null)
         {
             if (r._state != RoomState.Ready || r._leader == player._slotId)
             {
                 return;
             }
             List <Account> allPlayers = r.getAllPlayers();
             if (allPlayers.Count == 0)
             {
                 return;
             }
             if (player.access >= AccessLevel.GameMaster)
             {
                 this.ChangeLeader(r, allPlayers, player._slotId);
             }
             else
             {
                 if (!r.requestHost.Contains(player.player_id))
                 {
                     r.requestHost.Add(player.player_id);
                     if (r.requestHost.Count() < allPlayers.Count / 2 + 1)
                     {
                         using (ROOM_GET_HOST_PAK roomGetHostPak = new ROOM_GET_HOST_PAK(player._slotId))
                             this.SendPacketToRoom((SendPacket)roomGetHostPak, allPlayers);
                     }
                 }
                 if (r.requestHost.Count() < allPlayers.Count / 2 + 1)
                 {
                     return;
                 }
                 this.ChangeLeader(r, allPlayers, player._slotId);
             }
         }
         else
         {
             this._client.SendPacket((SendPacket) new ROOM_GET_HOST_PAK(2147483648U));
         }
     }
     catch (Exception ex)
     {
         Logger.info("ROOM_REQUEST_HOST_REC: " + ex.ToString());
     }
 }