public GameSessionInfo(
     GameSessionType sessionType,
     long uniqueId,
     string missionInternalName = "",
     int sideIndex             = -1,
     DifficultyRank difficulty = DifficultyRank.NONE,
     Dictionary <int, bool> globalFlagValues = null,
     bool isCheatSession = false)
 {
     SessionType         = sessionType;
     UniqueId            = uniqueId;
     MissionInternalName = missionInternalName;
     SideIndex           = sideIndex;
     Difficulty          = difficulty;
     GlobalFlagValues    = globalFlagValues;
     IsCheatSession      = isCheatSession;
 }
 public SessionCreateRequestPacket(GameSessionType sessionType)
 {
     SessionType = sessionType;
 }
Ejemplo n.º 3
0
    void OnGUI()
    {
        if(NetworkRefs.Lobby.Scene == null || !_drawing)
            return;

        if(NetworkRefs.GameSessions.Count > 0 && _selectedScene > (NetworkRefs.GameSessions.Count-1))
        {
            _selectedScene = (NetworkRefs.GameSessions.Count-1);
        }

        GUILayout.BeginArea(new Rect(Screen.width * panelLeft, Screen.height * panelTop, Screen.width * panelWidth, Screen.height * panelHeight));

        GUILayout.BeginVertical();

            // GameSessions and players Listings
            GUILayout.BeginHorizontal();

                // Listing of GameSessions
                GUILayout.BeginVertical();
                GUILayout.Label("Game sessions : ");
                for(int i = 0; i < NetworkRefs.GameSessions.Count; i++)
                {
                    var label = i == _selectedScene ? "\t" + NetworkRefs.GameSessions[i].Name.ToString() : NetworkRefs.GameSessions[i].Name.ToString();
                    GUILayout.Label(label);
                }
                GUILayout.EndVertical();

                // Listing of our current GameSession players
                if(NetworkRefs.GameSessions.Count > 0)
                {
                    GUILayout.BeginVertical();
                    GUILayout.Label(NetworkRefs.GameSessions[_selectedScene].Name+" players : ");
                    GUILayout.BeginScrollView(Vector2.zero);
                    foreach( string s in NetworkRefs.GameSessions[_selectedScene].Players)
                    {
                        GUILayout.Label(s);
                    }
                    GUILayout.EndScrollView();
                    GUILayout.EndVertical();
                }   

                // Listing of players connected to our games
                GUILayout.BeginVertical();
                GUILayout.Label("Lobby Players : ");
                GUILayout.BeginScrollView(Vector2.zero);
                foreach( string s in NetworkRefs.LobbyPlayers)
                {
                    GUILayout.Label(s);
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            // GameSession Management interface
            GUILayout.BeginHorizontal();
            if(GUILayout.Button("<", GUILayout.MaxWidth(Screen.width * 0.05f)) && (int)_gsType > 0)
            {
                _gsType -= 1; 
            }
            
            GUILayout.Label(_gsType.ToString(), GUILayout.MaxWidth(Screen.width * 0.1f));
            
            if(GUILayout.Button(">", GUILayout.MaxWidth(Screen.width * 0.05f)) && (int)_gsType < Enum.GetNames(typeof(GameSessionType)).Length-1 )
            {
                _gsType += 1; 
            }
            
            // Creation of a new GameSession
            if(GUILayout.Button("Create session", GUILayout.MaxWidth(Screen.width * 0.2f)) && NetworkRefs.Lobby.Scene != null)
            {
                NetworkRefs.Lobby.Scene.SendRequest<StartDto, ConnectionAnswer>("create.gameSession", new StartDto{ Name = NetworkRefs.Username+"'s "+_gsType.ToString(), Type = (int)_gsType }).Subscribe(
                answer =>
                {
                    if(!answer.ConnectionSuccess)
                    {
                        Debug.LogError(answer.ErrorMessage);
                        return;
                    }
                    NetworkRefs.Token = answer.Token;
                    NetworkRefs.Lobby.QueueOnMainThread( LoadGameSession );
                    
                });

            }
            
            // Joining a GameSession
            if(GUILayout.Button("Rejoin session", GUILayout.MaxWidth(Screen.width * 0.2f)) && NetworkRefs.Lobby.Scene != null && NetworkRefs.GameSessions.Count > 0)
            {
                NetworkRefs.Lobby.Scene.SendRequest<JoinDto, ConnectionAnswer>("join.gameSession", new JoinDto{ Room = NetworkRefs.GameSessions[_selectedScene].Id }).Subscribe(
                answer =>
                {
				
				Debug.Log("plop" + answer.ConnectionSuccess);
                    if(!answer.ConnectionSuccess)
                    {
                        Debug.LogError(answer.ErrorMessage);
                        return;
                    }
                    NetworkRefs.Token = answer.Token;
                    NetworkRefs.Lobby.QueueOnMainThread( LoadGameSession );               
                });
            }
            GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.EndArea();

    }
Ejemplo n.º 4
0
 public GameSessionConfig(string name, int maxPlayers, GameSessionType sessionType)
 {
     Name        = name;
     MaxPlayers  = maxPlayers;
     SessionType = sessionType;
 }
        public static GameSessionInfo ParseFromFile(string path)
        {
            if (File.Exists(path))
            {
                byte[] data = File.ReadAllBytes(path);
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = (byte)~data[i];
                }

                string   dataAsString = Encoding.UTF8.GetString(data);
                string[] parts        = dataAsString.Split(',');
                if (parts.Length < MIN_EXPECTED_FIELD_COUNT || parts.Length > EXPECTED_FIELD_COUNT)
                {
                    Logger.Log("Unexpected saved game meta file format in file " + path + ": " + dataAsString);
                    return(null);
                }

                GameSessionType sessionType = GameSessionType.UNKNOWN;

                int gameSessionTypeInt = Conversions.IntFromString(parts[0], -1);
                if (gameSessionTypeInt > -1 && gameSessionTypeInt <= (int)GameSessionType.SESSION_TYPE_MAX)
                {
                    sessionType = (GameSessionType)gameSessionTypeInt;
                }

                if (!long.TryParse(parts[1], out long uniqueId))
                {
                    Logger.Log("FAILED to parse unique ID in saved game meta file " + path + ": " + dataAsString);
                    return(null);
                }

                string         missionInternalName = parts[3];
                int            sideIndex           = Conversions.IntFromString(parts[4], -1);
                int            difficultyInt       = Conversions.IntFromString(parts[5], 0);
                DifficultyRank difficulty          = (difficultyInt <0 || difficultyInt> (int) DifficultyRank.HARD) ? DifficultyRank.NONE : (DifficultyRank)difficultyInt;

                Dictionary <int, bool> globalFlagsDictionary = null;
                if (parts.Length >= 7 && parts[6] != GLOBAL_FLAGS_NONE)
                {
                    string[] globalFlagParts = parts[6].Split('|');
                    globalFlagsDictionary = new Dictionary <int, bool>();

                    foreach (string gflagInfo in globalFlagParts)
                    {
                        string[] globalIndexAndState = gflagInfo.Split(':');
                        if (globalIndexAndState.Length != 2)
                        {
                            Logger.Log("FAILED to parse global flag index and state from game session info: " + gflagInfo + ", complete string: " + parts[6]);
                            continue;
                        }

                        int  globalIndex = int.Parse(globalIndexAndState[0], CultureInfo.InvariantCulture);
                        bool globalState = globalIndexAndState[1] == "1";

                        globalFlagsDictionary.Add(globalIndex, globalState);
                    }
                }

                bool isCheatSession = false;
                if (parts.Length >= 8)
                {
                    isCheatSession = parts[7] == "1";
                }

                return(new GameSessionInfo(sessionType, uniqueId, missionInternalName, sideIndex, difficulty, globalFlagsDictionary, isCheatSession));
            }

            return(null);
        }