Beispiel #1
0
 public void OnPressedBackWaitingtoBegin()
 {
     CurrentState = LobbyStates.READY_UP_STATE;
     roleValue    = 0;
     blackhatButton.image.color = originaBlkButtonColor;
     whitehatButton.image.color = originalWhtButtonColor;
     UpdateLobbyPlayerChanges();
 }
Beispiel #2
0
 public void OnJoinOrHostDoneButtonSelected()
 {
     CurrentState = HostOrJoinState;
     if (HostOrJoinState == LobbyStates.READY_UP_STATE)
     {
         network.LauchHost(true);
     }
 }
Beispiel #3
0
 public GameContext(List <Paddle> players, Ball ball, GameMap currentMap, ScoreBoard scoreBoard, LobbyStates lobbyState)
 {
     Players           = players;
     Ball              = ball;
     CurrentMap        = currentMap;
     ScoreBoard        = scoreBoard;
     LobbyState        = lobbyState;
     BlocksHaveChanged = false;
 }
Beispiel #4
0
 /// <summary>
 /// Called by UI to stop searching for a room to join
 /// </summary>
 public void StopPlay()
 {
     if (PhotonNetwork.connected && PhotonNetwork.room != null)
     {
         lobbyState = LobbyStates.none;
         PhotonNetwork.LeaveRoom();
         searchingLabel.OnSearchingStop();
         championSelect.OnStop();
     }
 }
Beispiel #5
0
    private void Start()
    {
        CurrentState                      = LobbyStates.JOIN_OR_HOST;
        orginialReadyButtonColor          = readyUpDoneButton.image.color;
        orginiallobbyListDoneButtonColor  = lobbyListDoneButton.image.color;
        originalJoinByIpDoneButton        = joinByIpDoneButton.image.color;
        originalJoinButtonColor           = joinButton.image.color;
        orginialHostButtonColor           = hostButton.image.color;
        originalColorhostOrjoinDoneButton = hostOrjoinDoneButton.image.color;

        originaBlkButtonColor  = blackhatButton.image.color;
        originalWhtButtonColor = whitehatButton.image.color;

        HostOrJoinState = LobbyStates.JOIN_OR_HOST;
    }
Beispiel #6
0
    /// <summary>
    /// Called by UI buttons; will queue the player based on the given map name
    /// </summary>
    /// <param name="mapName">The name of the map to put the player in</param>
    public void Play(string mapName)
    {
        gameHandler.currentMap = mapManager.GetMap(mapName);

        // Check to see if we are on the network and not already in a room
        if (PhotonNetwork.connected && PhotonNetwork.room == null)
        {
            // Find a room to join
            lobbyState = LobbyStates.searching;

            // Set room properties so that we can be found by other players looking for the same game (equivalent to matchmaking)
            Hashtable expectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable()
            {
                { "m", gameHandler.currentMap.name }
            };
            PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, 0);
        }
    }
Beispiel #7
0
 private void ProcessLobbiesCommand(ulong channelId, string name)
 {
     try {
         var channelName = Channels[channelId];
         if (_config.PrivateChat == channelName)
         {
             DotaClient.QueueChatMessage(channelId, String.Format(_config.LobbiesCommandNotAllowed, name), false);
         }
         else
         {
             var lobbies = LobbyStates.Where(l => _config.Games.Any(g => g.Chat == channelName && g.Maps.Any(m => m.MapId == l.CustomMapName)));
             if (lobbies.Count() == 0)
             {
                 DotaClient.QueueChatMessage(channelId, String.Format(_config.HostingNoLobbiesMessage, name), false);
             }
             else
             {
                 foreach (var lobby in lobbies)
                 {
                     var region    = _config.ServerRegions.Where(r => r.ServerId == lobby.ServerId).SingleOrDefault();
                     var game      = _config.Games.Where(g => g.Maps.Any(m => m.MapId == lobby.CustomMapName)).SingleOrDefault();
                     var lobbyName = game.Name;
                     if (game.Maps.Count > 1)
                     {
                         lobbyName += " " + game.Maps.Where(m => m.MapId == lobby.CustomMapName).FirstOrDefault().Name;
                     }
                     if (lobby.LobbyId != 0)
                     {
                         DotaClient.QueueChatMessage(channelId, String.Format(_config.HostingLobby, lobbyName, region.LongName), true);
                         DotaClient.QueueLobbyShare(channelId, lobby.LobbyId, game.CustomGameMode, true);
                     }
                     else
                     {
                         DotaClient.QueueChatMessage(channelId, String.Format(_config.LobbyQueuedMessage, lobbyName, region.LongName), true);
                     }
                 }
             }
         }
     } catch (Exception e) {
         _logger.Error("Error while processing !lobbies command", e);
     }
 }
Beispiel #8
0
    // Called every frame; checks to see whether a room is full
    void Update()
    {
        if (PhotonNetwork.connected)
        {
            if (PhotonNetwork.room != null)
            {
                if (lobbyState == LobbyStates.searching)
                {
                    // Wait for players
                    if (PhotonNetwork.room.PlayerCount == PhotonNetwork.room.MaxPlayers)
                    {
                        searchingLabel.OnSearchingPause();
                        championSelect.OnStart();
                        lobbyState = LobbyStates.championSelect;
                        StartCoroutine(UpdateGameID());

                        // Host player to instantiate the map for all players in the room
                        if (PhotonNetwork.isMasterClient)
                        {
                            PhotonNetwork.room.IsVisible = false;
                            PhotonNetwork.Instantiate(gameHandler.currentMap.map.name, gameHandler.currentMap.map.transform.position, gameHandler.currentMap.map.transform.rotation, 0);
                        }
                    }
                }

                if (lobbyState == LobbyStates.championSelect)
                {
                    // Return to searching if a player has left
                    if (PhotonNetwork.room.PlayerCount < PhotonNetwork.room.MaxPlayers)
                    {
                        lobbyState = LobbyStates.searching;
                        searchingLabel.OnSearchingStart();
                        championSelect.OnStop();
                    }
                }
            }
        }
    }
Beispiel #9
0
 public void OnLaunchNetworkDiscovery()
 {
     CurrentState = LobbyStates.NETWORK_DISCOVERY_STATE;
     NetworkDiscoveryManager.inst.StartAsClient();
 }
Beispiel #10
0
 public void OnJoinByIpDoneSelected()
 {
     network.networkValues.ip = IpInputField.text;
     network.LauchClient();
     CurrentState = LobbyStates.READY_UP_STATE;
 }
Beispiel #11
0
 public void OnReadyUpDoneButtonSelected()
 {
     CurrentState = LobbyStates.WAITING_TO_BEGIN_STATE;
     UpdateLobbyPlayerChanges();
 }
Beispiel #12
0
 public void OnJoinButtonSelected()
 {
     HostOrJoinState        = LobbyStates.JOIN_BY_IP_STATE;
     hostButton.image.color = orginialHostButtonColor;
     joinButton.image.color = new Color(originalJoinButtonColor.r * 1.25f, originalJoinButtonColor.g * 1.25f, originalJoinButtonColor.b * 1.25f, 1);
 }
Beispiel #13
0
 /// <summary>
 /// Sets the local player's current state in the lobby
 /// </summary>
 /// <param name="lobbyStates">The state to set the value to</param>
 public void SetLobbyState(LobbyStates lobbyStates)
 {
     lobbyState = lobbyStates;
 }
Beispiel #14
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);
     }
 }