private void OnPathComputed(PathComputer pathResult)
    {
        // If the path find succeeded, the entity will set the new destination and start walking toward it
        if (pathResult.ResultCode == PathComputer.eResult.success)
        {
            // Tell the server where we would like to go
            AsyncJSONRequest            serverRequest  = AsyncJSONRequest.Create(m_requestOwnerObject);
            Dictionary <string, object> requestPayload = new Dictionary <string, object>();

            requestPayload["character_id"] = m_entity.MyCharacterData.character_id;
            requestPayload["x"]            = OriginPortalEntryPoint.x;
            requestPayload["y"]            = OriginPortalEntryPoint.y;
            requestPayload["z"]            = OriginPortalEntryPoint.z;
            requestPayload["angle"]        = pathResult.DestinationFacingAngle;
            requestPayload["portal_id"]    = OriginPortal.portal_id;

            Status = eRequestStatus.pending_server_response;

            serverRequest.POST(
                ServerConstants.characterPortalRequestURL,
                requestPayload,
                this.OnServerRequestComplete);
        }
        else
        {
            Status        = eRequestStatus.completed;
            ResultCode    = eResult.failed_path;
            ResultDetails = "Path Failure Code: " + pathResult.ResultCode.ToString();

            // Notify the caller that the request is completed
            m_onCompleteCallback(this);
        }
    }
示例#2
0
    public void RequestCharacterList()
    {
        if (!IsCharacterListRequestPending)
        {
            AsyncJSONRequest            gameListRequest = AsyncJSONRequest.Create(m_selectCharacterController.gameObject);
            Dictionary <string, object> request         = new Dictionary <string, object>();

            request["username"] = SessionData.GetInstance().UserName;

            IsCharacterListRequestPending = true;

            gameListRequest.POST(
                ServerConstants.characterListRequestURL,
                request,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        SessionData sessionData = SessionData.GetInstance();
                        JsonData characterList  = response["character_list"];

                        sessionData.CharacterList = new List <CharacterData>();
                        for (int listIndex = 0; listIndex < characterList.Count; listIndex++)
                        {
                            sessionData.CharacterList.Add(CharacterData.FromObject(characterList[listIndex]));
                        }

                        if (sessionData.CharacterList.Count > 0)
                        {
                            SelectedListIndex = 0;
                        }

                        m_selectCharacterController.OnCharacterListUpdated();
                    }
                    else
                    {
                        m_selectCharacterController.OnRequestFailed(responseResult);
                        Debug.LogError("Get Character List Failed: " + asyncRequest.GetFailureReason());
                    }
                }
                else
                {
                    m_selectCharacterController.OnRequestFailed("Connection Failure!");
                    Debug.LogError("Get Game List Failed: " + asyncRequest.GetFailureReason());
                }

                IsCharacterListRequestPending = false;
            });
        }
    }
    public void CreateGame(
        string gameName,
        GameConstants.eDungeonSize dungeonSize,
        GameConstants.eDungeonDifficulty dungeonDifficulty,
        string ircServer,
        uint ircPort,
        bool ircEnabled,
        bool ircEncryptionEnabled)
    {
        if (!IsGameCreateRequestPending)
        {
            AsyncJSONRequest            gameCreateRequest = AsyncJSONRequest.Create(m_createGameController.gameObject);
            Dictionary <string, object> requestParameters = new Dictionary <string, object>();

            requestParameters["game_name"]              = gameName;
            requestParameters["irc_enabled"]            = ircEnabled;
            requestParameters["irc_server"]             = ircServer;
            requestParameters["irc_port"]               = ircPort;
            requestParameters["irc_encryption_enabled"] = ircEncryptionEnabled;
            requestParameters["dungeon_size"]           = (int)dungeonSize;
            requestParameters["dungeon_difficulty"]     = (int)dungeonDifficulty;

            IsGameCreateRequestPending = true;

            gameCreateRequest.POST(
                ServerConstants.gameCreateRequestURL,
                requestParameters,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        m_createGameController.OnGameCreated();
                    }
                    else
                    {
                        m_createGameController.OnRequestFailed(responseResult);
                        Debug.LogError("Create Game Failed: " + asyncRequest.GetFailureReason());
                    }
                }
                else
                {
                    m_createGameController.OnRequestFailed("Connection Failure!");
                    Debug.LogError("Create Game Failed: " + asyncRequest.GetFailureReason());
                }

                IsGameCreateRequestPending = false;
            });
        }
    }
    public void RequestCharacterPing()
    {
        if (!IsCharacterPingRequestPending)
        {
            AsyncJSONRequest            characterPingRequest = AsyncJSONRequest.Create(m_gameWorldController.gameObject);
            Dictionary <string, object> request = new Dictionary <string, object>();

            request["character_id"] = SessionData.GetInstance().CharacterID;

            IsCharacterPingRequestPending = true;

            characterPingRequest.POST(
                ServerConstants.characterPingRequestURL,
                request,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = JsonUtilities.ParseString(response, "result");

                    if (responseResult == "Success")
                    {
                        GameData gameData = SessionData.GetInstance().CurrentGameData;

                        // Parse the game events into the session data
                        Debug.Log("Game Events Received");
                        gameData.ParseEventResponse(response);

                        // If there were new events, notify the controller so that
                        // it can start playing the events back
                        if (!gameData.IsEventCursorAtLastEvent)
                        {
                            m_gameWorldController.OnGameHasNewEvents();
                        }
                    }
                    else
                    {
                        Debug.LogError("Character Ping Request Failed: " + responseResult);
                        m_gameWorldController.OnRequestFailed(responseResult);
                    }
                }
                else
                {
                    Debug.LogError("Game Ping Request Failed: " + asyncRequest.GetFailureReason());
                    m_gameWorldController.OnRequestFailed("Connection Failed!");
                }

                IsCharacterPingRequestPending = false;
            });
        }
    }
    public void RequestGameList()
    {
        if (!IsGameListRequestPending)
        {
            AsyncJSONRequest gameListRequest = AsyncJSONRequest.Create(m_selectGameController.gameObject);

            IsGameListRequestPending = true;

            gameListRequest.GET(
                ServerConstants.gameListRequestURL,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        SessionData sessionData = SessionData.GetInstance();
                        JsonData gamesList      = response["game_list"];

                        sessionData.GameList = new List <GameResponseEntry>();
                        for (int listIndex = 0; listIndex < gamesList.Count; listIndex++)
                        {
                            sessionData.GameList.Add(GameResponseEntry.FromObject(gamesList[listIndex]));
                        }

                        if (sessionData.GameList.Count > 0)
                        {
                            SelectedListIndex = 0;
                        }

                        m_selectGameController.OnGameListUpdated();
                    }
                    else
                    {
                        m_selectGameController.OnRequestFailed(responseResult);
                        Debug.LogError("Get Game List Failed: " + asyncRequest.GetFailureReason());
                    }
                }
                else
                {
                    m_selectGameController.OnRequestFailed("Connection Failure!");
                    Debug.LogError("Get Game List Failed: " + asyncRequest.GetFailureReason());
                }

                IsGameListRequestPending = false;
            });
        }
    }
    public void RequestFullGameState()
    {
        if (!IsFullGameStateRequestPending)
        {
            AsyncJSONRequest            fullGameStateRequest = AsyncJSONRequest.Create(m_gameWorldController.gameObject);
            Dictionary <string, object> request = new Dictionary <string, object>();

            request["character_id"] = SessionData.GetInstance().CharacterID;

            IsFullGameStateRequestPending = true;

            fullGameStateRequest.POST(
                ServerConstants.fullGameStateRequestURL,
                request,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        GameData currentGameData = SessionData.GetInstance().CurrentGameData;

                        // Parse the full world state into the session data
                        currentGameData.ParseFullGameStateResponse(response);

                        Debug.Log("Game State Loaded");
                        m_gameWorldController.OnGameLoaded();
                    }
                    else
                    {
                        Debug.LogError("Game State Request Failed: " + responseResult);
                        m_gameWorldController.OnRequestFailed(responseResult);
                    }
                }
                else
                {
                    Debug.LogError("Game State Request Failed: " + asyncRequest.GetFailureReason());
                    m_gameWorldController.OnRequestFailed("Connection Failed!");
                }

                IsFullGameStateRequestPending = false;
            });
        }
    }
示例#7
0
    public void RequestCreateAccount(
        string uname,
        string password,
        string email)
    {
        string encryptedPassword = ClientUtilities.HashPassword(password);

        IsCreateAccountRequestPending = true;

        Dictionary <string, object> requestParameters = new Dictionary <string, object>();

        requestParameters["username"]     = uname;
        requestParameters["password"]     = encryptedPassword;
        requestParameters["emailAddress"] = email;

        AsyncJSONRequest createAccountRequest = AsyncJSONRequest.Create(m_createAccountController.gameObject);

        createAccountRequest.POST(
            ServerConstants.createAccountRequestURL,
            requestParameters,
            (AsyncJSONRequest request) =>
        {
            if (request.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
            {
                JsonData createAccountResponse = request.GetResult();
                string result = (string)createAccountResponse["result"];

                if (result.StartsWith("Success"))
                {
                    m_createAccountController.OnCreateAccountSucceeded(result);
                }
                else
                {
                    m_createAccountController.OnCreateAccountFailed(result);
                }
            }
            else
            {
                m_createAccountController.OnCreateAccountFailed("Connection Failure!");
                Debug.LogError("Create Account Failed: " + request.GetFailureReason());
            }

            IsCreateAccountRequestPending = false;
        });
    }
    public void CreateCharacter(
        string characterName)
    {
        if (!IsCharacterCreateRequestPending)
        {
            AsyncJSONRequest            gameCreateRequest = AsyncJSONRequest.Create(m_createCharacterController.gameObject);
            Dictionary <string, object> requestParameters = new Dictionary <string, object>();

            requestParameters["name"]       = characterName;
            requestParameters["archetype"]  = (int)GetArchetype();
            requestParameters["gender"]     = (int)GetGender();
            requestParameters["picture_id"] = GetPictureId();

            IsCharacterCreateRequestPending = true;

            gameCreateRequest.POST(
                ServerConstants.characterCreateRequestURL,
                requestParameters,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        m_createCharacterController.OnCharacterCreated();
                    }
                    else
                    {
                        m_createCharacterController.OnRequestFailed(responseResult);
                        Debug.LogError("Create Character Failed: " + asyncRequest.GetFailureReason());
                    }
                }
                else
                {
                    m_createCharacterController.OnRequestFailed("Connection Failure!");
                    Debug.LogError("Create Character Failed: " + asyncRequest.GetFailureReason());
                }

                IsCharacterCreateRequestPending = false;
            });
        }
    }
示例#9
0
    public void RequestBindCharacterToGame()
    {
        SessionData sessionData = SessionData.GetInstance();

        if (!IsCharacterBindRequestPending && sessionData.GameList.Count > 0)
        {
            AsyncJSONRequest            gameDeleteRequest = AsyncJSONRequest.Create(m_selectCharacterController.gameObject);
            Dictionary <string, object> requestParameters = new Dictionary <string, object>();

            requestParameters["character_id"] = sessionData.CharacterID;
            requestParameters["game_id"]      = sessionData.GameID;

            IsCharacterBindRequestPending = true;

            gameDeleteRequest.POST(
                ServerConstants.bindCharacterToGameRequestURL,
                requestParameters,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        // Request an updated character list now that we deleted a game
                        m_selectCharacterController.OnCharacterBoundToGame();
                    }
                    else
                    {
                        m_selectCharacterController.OnRequestFailed(responseResult);
                        Debug.LogError("Bind CharacterTo Game Failed: " + asyncRequest.GetFailureReason());
                    }
                }
                else
                {
                    m_selectCharacterController.OnRequestFailed("Connection Failure!");
                    Debug.LogError("Bind CharacterTo Game Failed: " + asyncRequest.GetFailureReason());
                }

                IsCharacterBindRequestPending = false;
            });
        }
    }
    public void RequestLogout()
    {
        if (!IsLogoutRequestPending)
        {
            AsyncJSONRequest            gameListRequest = AsyncJSONRequest.Create(m_gameWorldController.gameObject);
            Dictionary <string, object> request         = new Dictionary <string, object>();

            request["username"] = SessionData.GetInstance().UserName;

            IsLogoutRequestPending = true;

            gameListRequest.POST(
                ServerConstants.logoutRequestURL,
                request,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        m_gameWorldController.OnLogoutComplete();
                    }
                    else
                    {
                        m_gameWorldController.OnRequestFailed(responseResult);
                        Debug.LogError("Logout Request Failed: " + asyncRequest.GetFailureReason());
                    }
                }
                else
                {
                    m_gameWorldController.OnRequestFailed("Connection Failure!");
                    Debug.LogError("Logout Request Failed: " + asyncRequest.GetFailureReason());
                }

                IsLogoutRequestPending = false;
            });
        }
    }
示例#11
0
    public void RequestLogin(string uname, string password)
    {
        // Hash the password before sending over the wire
        string encryptedPasswordString = ClientUtilities.HashPassword(password);

        LoginRequestPending = true;

        {
            // Allocate an async request on the login controller
            AsyncJSONRequest            loginRequest      = AsyncJSONRequest.Create(m_loginController.gameObject);
            Dictionary <string, object> requestParameters = new Dictionary <string, object>();

            requestParameters["username"] = uname;
            requestParameters["password"] = encryptedPasswordString;

            loginRequest.POST(
                ServerConstants.loginRequestURL,
                requestParameters,
                this.OnLoginRequestComplete);
        }
    }
    public void RequestRoomData(RoomKey roomKey, GameEvent.OnEventCompleteDelegate onComplete)
    {
        if (!IsRoomDataRequestPending)
        {
            // Cached room data is available
            if (SessionData.GetInstance().CurrentGameData.HasRoomData(roomKey))
            {
                // Update which room we're currently in
                SessionData.GetInstance().CurrentGameData.CurrentRoomKey = roomKey;

                // Notify the controller
                Debug.Log("Using cached room data");
                m_gameWorldController.OnRoomLoaded(roomKey);

                // Notify the caller
                if (onComplete != null)
                {
                    onComplete();
                }
            }
            // Have to request room data from the server
            else
            {
                AsyncJSONRequest            roomDataRequest = AsyncJSONRequest.Create(m_gameWorldController.gameObject);
                Dictionary <string, object> request         = new Dictionary <string, object>();

                request["game_id"] = SessionData.GetInstance().GameID;
                request["room_x"]  = roomKey.x;
                request["room_y"]  = roomKey.y;
                request["room_z"]  = roomKey.z;

                IsRoomDataRequestPending = true;

                roomDataRequest.POST(
                    ServerConstants.roomDataRequestURL,
                    request,
                    (AsyncJSONRequest asyncRequest) =>
                {
                    if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                    {
                        JsonData response     = asyncRequest.GetResult();
                        string responseResult = (string)response["result"];

                        if (responseResult == "Success")
                        {
                            SessionData sessionData = SessionData.GetInstance();
                            GameData currentGame    = sessionData.CurrentGameData;
                            RoomData roomData       = RoomData.FromObject(response);

                            // Add the room data to the room cache
                            currentGame.SetCachedRoomData(roomData.RoomKey, roomData);

                            // Update which room we're currently in
                            currentGame.CurrentRoomKey = roomKey;

                            // Notify the controller
                            Debug.Log("Room Loaded");
                            m_gameWorldController.OnRoomLoaded(roomData.RoomKey);
                        }
                        else
                        {
                            Debug.Log("Room Data Request Failed: " + responseResult);
                            m_gameWorldController.OnRequestFailed(responseResult);
                        }
                    }
                    else
                    {
                        Debug.Log("Room Data Request Failed: " + asyncRequest.GetFailureReason());
                        m_gameWorldController.OnRequestFailed("Connection Failed!");
                    }

                    // Notify the caller
                    if (onComplete != null)
                    {
                        onComplete();
                    }

                    IsRoomDataRequestPending = false;
                });
            }
        }
    }