示例#1
0
        protected override void DoWrite(ChannelOutboundBuffer input)
        {
            for (;;)
            {
                var msg = input.Current;
                if (msg == null)
                {
                    break;
                }

                ReferenceCountUtil.Retain(msg);
                OutboundMessages.Enqueue(msg);
                input.Remove();
            }
        }
示例#2
0
 public void Cancel(CCancel cancel)
 {
     _cancelRequested = true;
     OutboundMessages.Enqueue(cancel);
 }
示例#3
0
 private void ProcessLobbyCommand(ulong channelId, ulong accountId, string name, string text)
 {
     try {
         var commandParams = text.Split(' ');
         var channelName   = Channels[channelId];
         var game          = _config.Games.Where(m => m.Chat.ToLower() == channelName.ToLower()).SingleOrDefault();
         if (channelName == _config.PrivateChat)
         {
             DotaClient.QueueChatMessage(channelId, String.Format("{0}, requesting a lobby in this channel is not allowed, please request a lobby in custom game's public channel.", name, GetValidServerRegions()), false);
         }
         else if (commandParams.Length < 2)
         {
             DotaClient.QueueChatMessage(channelId, String.Format("{0}, please specify server region. Regions: {1}.", name, GetValidServerRegions()), false);
             if (game.Maps.Count > 1)
             {
                 DotaClient.QueueChatMessage(channelId, String.Format(_config.SpecifyMapMessage, name, GetValidMaps(game), _config.ServerRegions.FirstOrDefault().ShortName, game.Maps.FirstOrDefault().ChatId), false);
             }
         }
         else
         {
             var region = _config.ServerRegions.Where(sr => sr.ShortName == commandParams[1].Trim().ToLower()).SingleOrDefault();
             if (region == null)
             {
                 DotaClient.QueueChatMessage(channelId, String.Format("{0}, invalid server region. Valid regions: {1}.", name, GetValidServerRegions()), false);
             }
             else
             {
                 string mapName = null;
                 if (commandParams.Length > 2 && game.Maps.Count > 1)
                 {
                     mapName = commandParams[2];
                 }
                 Map  map   = null;
                 bool mapOk = true;
                 if (mapName == null)
                 {
                     map = game.Maps.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
                 }
                 else
                 {
                     map = game.Maps.Where(m => m.ChatId == mapName.Trim().ToLower()).FirstOrDefault();
                     if (map == null && game.Maps.Count > 1)
                     {
                         mapOk = false;
                         DotaClient.QueueChatMessage(channelId, String.Format(_config.MapNotFoundMessage, name, GetValidMaps(game)), false);
                     }
                 }
                 if (mapOk)
                 {
                     using (IRepository repository = new Repository(_dbOptions)) {
                         var banned = repository.Bans.Any(b => b.Account.AccountId == accountId.ToString() && b.Expires > DateTime.UtcNow);
                         if (!banned || _config.Admins.Contains(accountId))
                         {
                             try {
                                 var timedoutLobbies = LobbyStates.Where(ls => ls.Created.AddMinutes(_config.Games.Where(g => g.Maps.Any(m => m.MapId == ls.CustomMapName)).SingleOrDefault().LobbyTimeout + 1) < DateTime.UtcNow);
                                 foreach (var timedoutLobby in timedoutLobbies.ToList())
                                 {
                                     _logger.Info("Removed timed out lobby - Game: " + timedoutLobby.CustomMapName + " Server ID: " + timedoutLobby.CustomMapName);
                                     LobbyStates.Remove(timedoutLobby);
                                 }
                             } catch (Exception e) {
                                 _logger.Error("Error while checking timed out lobbies", e);
                             }
                             var myExistingLobby = LobbyStates.Where(ls => ls.RequesterAccountId == accountId).FirstOrDefault();
                             if (myExistingLobby != null)
                             {
                                 DotaClient.QueueChatMessage(channelId, String.Format(_config.LobbyRequesterHasHost, name, _config.Games.Where(g => g.Maps.Any(m => m.MapId == myExistingLobby.CustomMapName)).SingleOrDefault().Name), false);
                             }
                             else
                             {
                                 var existingLobby = LobbyStates.Where(ls => game.Maps.Any(m => m.MapId == ls.CustomMapName) && ls.ServerId == region.ServerId).FirstOrDefault();
                                 if (existingLobby != null)
                                 {
                                     if (existingLobby.LobbyId == 0)
                                     {
                                         DotaClient.QueueChatMessage(channelId, String.Format(_config.LobbyAlreadyQueued, name, region.LongName), false);
                                     }
                                     else
                                     {
                                         DotaClient.QueueChatMessage(channelId, String.Format(_config.LobbyAlreadyHosted, name, region.LongName), true);
                                         DotaClient.QueueLobbyShare(channelId, existingLobby.LobbyId, game.CustomGameMode, true);
                                     }
                                 }
                                 else
                                 {
                                     if (LobbyStates.Count < _config.LobbyBotsPool.Count)
                                     {
                                         DotaClient.QueueChatMessage(channelId, String.Format("{0}, hosting your lobby, just a sec...", name), false);
                                         game.ServerId    = region.ServerId;
                                         game.RequestedBy = accountId;
                                         _logger.Info("Queue lobby - Game: " + game.Name + " - Map: " + map.Name + " - Server ID: " + game.ServerId);
                                         OutboundMessages.Enqueue(new Message()
                                         {
                                             Id      = MessageIds.Out.CREATE_LOBBY,
                                             Payload = JsonConvert.SerializeObject(new LobbyHost()
                                             {
                                                 Game = game,
                                                 Map  = map
                                             })
                                         });
                                         lock (LobbyStates) { //Just in case should something here be multithreaded
                                             LobbyStates.Add(new LobbyState()
                                             {
                                                 CustomMapName      = map.MapId,
                                                 ServerId           = game.ServerId,
                                                 RequesterAccountId = accountId,
                                                 Created            = DateTime.UtcNow
                                             });
                                         }
                                     }
                                     else
                                     {
                                         DotaClient.QueueChatMessage(channelId, String.Format(_config.BusyMessage, name), false);
                                     }
                                 }
                             }
                         }
                         else if (banned)
                         {
                             DotaClient.QueueChatMessage(channelId, String.Format(_config.LobbyRequesterBanned, name), false);
                         }
                     }
                 }
             }
         }
     } catch (Exception e) {
         _logger.Error(String.Format("Error while processing !host command: {0}", text), e);
     }
 }