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;
            });
        }
    }
Example #2
0
        public static int CreateGame(
            AsyncRPGDataContext context,
            int account_id,
            string game_name,
            GameConstants.eDungeonSize dungeonSize,
            GameConstants.eDungeonDifficulty dungeonDifficulty,
            bool irc_enabled,
            string irc_server,
            int irc_port,
            bool irc_encryption_enabled)
        {
            int new_game_id = -1;

            // Create a random 256-bit (32 byte) encryption key for encrypting chat
            string irc_encryption_key = RNGUtilities.CreateNonDeterministicRandomBase64String(256);

            Debug.Assert(irc_encryption_key.Length == 44);

            if (irc_server.Length == 0)
            {
                irc_server = IrcConstants.DEFAULT_IRC_SERVER;
            }

            if (irc_port < IrcConstants.LOWEST_VALID_IRC_PORT || irc_port > IrcConstants.HIGHEST_VALID_IRC_PORT)
            {
                irc_port = IrcConstants.DEFAULT_IRC_PORT;
            }

            {
                Games newGame = new Games
                {
                    OwnerAccountID      = account_id,
                    Name                = game_name,
                    DungeonSize         = (int)dungeonSize,
                    DungeonDifficulty   = (int)dungeonDifficulty,
                    IrcEnabed           = irc_enabled,
                    IrcServer           = irc_server,
                    IrcPort             = irc_port,
                    IrcEncryptionKey    = irc_encryption_key,
                    IrcEncryptionEnabed = irc_encryption_enabled
                };

                context.Games.InsertOnSubmit(newGame);
                context.SubmitChanges();

                new_game_id = newGame.GameID;
            }

            return(new_game_id);
        }
    // UI Event Handlers
    public void OnGameCreateClicked()
    {
        audio.PlayOneShot(alertSound, 1.0f);

        if (!m_createGameModel.IsGameCreateRequestPending)
        {
            string name                   = createGameView.GetGameName();
            string irc_server             = createGameView.GetIrcServer();
            uint   irc_port               = createGameView.GetIrcPort();
            bool   irc_enabled            = createGameView.GetIrcEnabled();
            bool   irc_encryption_enabled = createGameView.GetIrcEncryptionEnabled();

            //TODO: Read the dungeon size from the game view
            GameConstants.eDungeonSize dungeon_size = GameConstants.eDungeonSize.small;

            //TODO: Read the dungeon difficulty from the game view
            GameConstants.eDungeonDifficulty dungeon_difficulty = GameConstants.eDungeonDifficulty.normal;

            if (name.Length == 0)
            {
                createGameView.SetStatusText("Enter a name!");
            }
            else if (irc_server.Length == 0)
            {
                createGameView.SetStatusText("Enter an IRC server address!");
            }
            else if (irc_port < ServerConstants.LOWEST_VALID_IRC_PORT || irc_port > ServerConstants.HIGHEST_VALID_IRC_PORT)
            {
                createGameView.SetStatusText("Enter a valid IRC server port!");
            }
            else
            {
                createGameView.SetStatusText("Creating...");
                m_createGameModel.CreateGame(
                    name,
                    dungeon_size,
                    dungeon_difficulty,
                    irc_server,
                    irc_port,
                    irc_enabled,
                    irc_encryption_enabled);
            }
        }
    }
Example #4
0
        public GameCreateRequestProcessor(
            int account_id,
            string game_name,
            GameConstants.eDungeonSize dungeon_size,
            GameConstants.eDungeonDifficulty dungeon_difficulty,
            bool irc_enabled,
            string irc_server,
            int irc_port,
            bool irc_encryption_enabled)
        {
            m_account_id             = account_id;
            m_game_name              = game_name;
            m_dungeon_size           = dungeon_size;
            m_dungeon_difficulty     = dungeon_difficulty;
            m_irc_enabled            = irc_enabled;
            m_irc_server             = irc_server;
            m_irc_port               = irc_port;
            m_irc_encryption_enabled = irc_encryption_enabled;

            m_new_game_id = -1;
        }
        public GameCreateRequestProcessor(
            int account_id,
            string game_name,
            GameConstants.eDungeonSize dungeon_size,
            GameConstants.eDungeonDifficulty dungeon_difficulty,
            bool irc_enabled,
            string irc_server,
            int irc_port,
            bool irc_encryption_enabled)
        {
            m_account_id = account_id;
            m_game_name= game_name;
            m_dungeon_size= dungeon_size;
            m_dungeon_difficulty = dungeon_difficulty;
            m_irc_enabled= irc_enabled;
            m_irc_server= irc_server;
            m_irc_port= irc_port;
            m_irc_encryption_enabled= irc_encryption_enabled;

            m_new_game_id = -1;
        }
Example #6
0
 public WorldTemplate(GameConstants.eDungeonSize size, GameConstants.eDungeonDifficulty difficulty)
 {
     dungeon_size       = size;
     dungeon_difficulty = difficulty;
 }
Example #7
0
 public WorldTemplate()
 {
     dungeon_size       = GameConstants.eDungeonSize.small;
     dungeon_difficulty = GameConstants.eDungeonDifficulty.normal;
 }
Example #8
0
 public WorldTemplate(GameConstants.eDungeonSize size, GameConstants.eDungeonDifficulty difficulty)
 {
     dungeon_size = size;
     dungeon_difficulty = difficulty;
 }
Example #9
0
 public WorldTemplate()
 {
     dungeon_size = GameConstants.eDungeonSize.small;
     dungeon_difficulty = GameConstants.eDungeonDifficulty.normal;
 }