Ejemplo n.º 1
0
    IEnumerator GuildMembersRequest(string guildId, LobbyMessageInfo info)
    {
        // Get guild members from database
        if (!GameDB.guildIdToGuildMembers.ContainsKey(guildId))
        {
            yield return(GuildsDB.GetGuildMembers(guildId));
        }

        // Send guild info to player
        if (GameDB.guildIdToGuildMembers.ContainsKey(guildId))
        {
            var guildMembers = GameDB.guildIdToGuildMembers[guildId];

            // Member names
            foreach (var member in guildMembers)
            {
                if (!GameDB.accountIdToName.TryGetValue(member.accountId, out member.name))
                {
                    yield return(LobbyGameDB.GetPlayerName(member.accountId, data => {
                        if (data != null)
                        {
                            member.name = data;
                            GameDB.accountIdToName[member.accountId] = data;
                        }
                    }));
                }
            }

            Lobby.RPC("ReceiveGuildMembers", info.sender, guildId, guildMembers.ToArray(), true);
        }
        else
        {
            Lobby.RPC("ReceiveGuildMembersError", info.sender, guildId);
        }
    }
Ejemplo n.º 2
0
    IEnumerator SetFriendNote(string friendName, string groupName, string note, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        LogManager.General.Log(string.Format("'{0}' sets friends list note for '{1}' to '{2}'", player.name, friendName, note));

        // Find friends group
        var selectedGroup = player.friends.GetGroupByName(groupName);

        // Get account ID
        string friendAccountId = null;

        yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => {
            friendAccountId = data;
        }));

        // Error getting account ID?
        if (friendAccountId == null)
        {
            Lobby.RPC("SetFriendNotePlayerDoesntExistError", info.sender, friendName);
            yield break;
        }

        // Remove player from the group
        selectedGroup.friends.Find(friend => friend.accountId == friendAccountId).note = note;

        // Save friends list in database
        yield return(FriendsDB.SetFriends(
                         player.accountId,
                         player.friends,
                         null
                         ));
    }
Ejemplo n.º 3
0
    // SendStaffInfo
    public static void SendStaffInfo(LobbyPlayer player)
    {
        LogManager.General.Log("Sending staff info to " + player.accessLevel + " '" + player.name + "' (" + player.account.name + ")...");

        // VIP and higher
        if (player.accessLevel >= AccessLevel.CommunityManager)
        {
            // Last logins
            LobbyGameDB.GetLastLogins(20, data => {
                if (data != null)
                {
                    Lobby.RPC("ReceiveLastLogins", player.peer, data, false);
                }
                else
                {
                    LogManager.DB.LogError("Couldn't fetch last logins!");
                }
            });

            // Last registrations
            LobbyGameDB.GetLastRegistrations(20, data => {
                if (data != null)
                {
                    Lobby.RPC("ReceiveLastRegistrations", player.peer, data, false);
                }
                else
                {
                    LogManager.DB.LogError("Couldn't fetch last registrations!");
                }
            });
        }
    }
Ejemplo n.º 4
0
    IEnumerator PlayerNameChange(string newName, LobbyMessageInfo info)
    {
        // Prettify to be safe
        newName = newName.PrettifyPlayerName();

        // Validate data
        if (!Validator.playerName.IsMatch(newName))
        {
            LogManager.General.LogError("Player name is not valid: '" + newName + "'");
            yield break;
        }

        // Check if name exists already
        yield return(LobbyGameDB.GetAccountIdByPlayerName(newName, data => {
            if (data != null)
            {
                Lobby.RPC("PlayerNameAlreadyExists", info.sender, newName);
            }
            else
            {
                // Get the account
                LobbyPlayer player = GetLobbyPlayer(info);

                // Change name
                LogManager.General.Log("Account " + player.accountId + " has requested to change its player name to '" + newName + "'");
                LobbyGameDB.SetPlayerName(player, newName);
            }
        }));
    }
Ejemplo n.º 5
0
 // Account registered
 void OnAccountRegistered(Account account)
 {
     // Save registration date in database
     LobbyGameDB.SetAccountRegistrationDate(
         account.id.value,
         System.DateTime.UtcNow
         );
 }
    IEnumerator ChangePassword(string newPassword, LobbyMessageInfo info)
    {
        // Get the account
        var player = LobbyServer.GetLobbyPlayer(info);

        // Change name
        LogManager.General.Log("Player '" + player.name + "' has requested to change its password.");
        yield return(StartCoroutine(LobbyGameDB.SetPassword(player, newPassword)));
    }
Ejemplo n.º 7
0
    void RequestPlayerEmail(string accountId, LobbyMessageInfo info)
    {
        LogManager.General.Log("Requested mail for: " + accountId);

        // Query email
        LobbyGameDB.GetEmail(accountId, data => {
            if (data != null)
            {
                Lobby.RPC("ReceivePlayerEmail", info.sender, accountId, data);
            }
        });
    }
Ejemplo n.º 8
0
 IEnumerator PlayerNameExists(string newName, LobbyMessageInfo info)
 {
     yield return(LobbyGameDB.GetAccountIdByPlayerName(newName, data => {
         if (data != null)
         {
             Lobby.RPC("PlayerNameAlreadyExists", info.sender, newName);
         }
         else
         {
             Lobby.RPC("PlayerNameFree", info.sender, newName);
         }
     }));
 }
 void ResendActivationMail(string email, LobbyMessageInfo info)
 {
     LobbyGameDB.GetAccountAwaitingActivation(
         email,
         (token) => {
         if (!string.IsNullOrEmpty(token))
         {
             SendActivationMail(email, token);
             Lobby.RPC("ActivationMailSent", info.sender);
         }
     }
         );
 }
Ejemplo n.º 10
0
    IEnumerator LeaveInstance(bool gameEnded, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        if (player.inMatch)
        {
            LogManager.General.Log("Player '" + player.name + "' returned from a match");

            if (gameEnded)
            {
                // Send him his new stats
                LobbyGameDB.GetPlayerStats(player);

                // Send him his new artifact inventory
                ArtifactsDB.GetArtifactInventory(player);

                // Update ranking list cache
                if (!player.match.updatedRankingList)
                {
                    RankingsServer.instance.StartRankingListCacheUpdate(player.match);
                    player.match.updatedRankingList = true;
                }
            }

            LeaveMatch(player);
        }
        else if (player.inFFA)
        {
            // Send him his new stats
            //StartCoroutine(lobbyGameDB.GetPlayerStats(player));

            // Update ranking list cache

            /*if(!player.match.updatedRankingList) {
             *      RankingsServer.instance.StartRankingListCacheUpdate(player.match);
             *      player.match.updatedRankingList = true;
             * }*/

            LeaveMatch(player);
        }
        else if (player.inTown || player.inWorld)
        {
            player.gameInstance = null;

            if (AccountManager.Master.IsLoggedIn(player.peer))
            {
                yield return(AccountManager.Master.LogOut(info.sender).WaitUntilDone());
            }
        }
    }
Ejemplo n.º 11
0
    IEnumerator AddFriend(string friendName, string groupName, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        LogManager.General.Log(string.Format("'{0}' added '{1}' to friend list group '{2}'", player.name, friendName, groupName));

        // Find friends group
        var selectedGroup = player.friends.GetGroupByName(groupName);

        // Get account ID
        string friendAccountId = null;

        yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => {
            friendAccountId = data;
        }));

        // Error getting account ID?
        if (friendAccountId == null)
        {
            Lobby.RPC("FriendAddPlayerDoesntExistError", info.sender, friendName);
            yield break;
        }

        // Trying to add yourself?
        if (friendAccountId == player.accountId)
        {
            Lobby.RPC("FriendAddCantAddYourselfError", info.sender, friendName);
            yield break;
        }

        // Already in friends list?
        if (!player.friends.CanAdd(friendAccountId))
        {
            Lobby.RPC("FriendAddAlreadyExistsError", info.sender, friendName);
            yield break;
        }

        // Add player to the group
        selectedGroup.friends.Add(new Friend(friendAccountId));

        // Send new friends list
        player.OnFriendsListLoaded();

        // Save friends list in database
        yield return(FriendsDB.SetFriends(
                         player.accountId,
                         player.friends,
                         null
                         ));
    }
    // DeleteAccount
    // TODO: This is incomplete and should only be used for not yet activated accounts
    public static IEnumerator DeleteAccount(string accountId)
    {
        string email = null;

        yield return(LobbyGameDB.GetEmail(
                         accountId,
                         data => {
            if (data != null)
            {
                email = data;
            }
        }
                         ));

        if (string.IsNullOrEmpty(email))
        {
            yield break;
        }

        // Get a list of all buckets
        var getBucketsReq = Bucket.GetBuckets();

        yield return(getBucketsReq.WaitUntilDone());

        if (getBucketsReq.isSuccessful)
        {
            foreach (var bucket in getBucketsReq.GetBucketEnumerable())
            {
                if (bucket.name.StartsWith("AccountTo"))
                {
                    yield return(bucket.Remove(accountId).WaitUntilDone());
                }
            }
        }

        var emailBucketNames = new string[] {
            "AccountsAwaitingActivation",
            "uLobby AccountNameToID"
        };

        foreach (var bucketName in emailBucketNames)
        {
            yield return(new Bucket(bucketName).Remove(email).WaitUntilDone());
        }

        yield return(new Bucket("uLobby Accounts").Remove(email).WaitUntilDone());
    }
Ejemplo n.º 13
0
    IEnumerator ViewProfile(string playerName, LobbyMessageInfo info)
    {
        LobbyPlayer playerRequesting = GetLobbyPlayer(info);

        yield return(LobbyGameDB.GetAccountIdByPlayerName(playerName, data => {
            if (data != null)
            {
                SendPublicAccountInfo(
                    data,                                       // Account ID
                    playerRequesting                            // Receiver
                    );
            }
            else
            {
                Lobby.RPC("ViewProfileError", info.sender, playerName);
            }
        }));
    }
Ejemplo n.º 14
0
    void RequestPlayerName(string accountId, LobbyMessageInfo info)
    {
        // Cached?
        string playerName;

        if (GameDB.accountIdToName.TryGetValue(accountId, out playerName))
        {
            Lobby.RPC("ReceivePlayerName", info.sender, accountId, playerName);
            return;
        }

        // Query name
        LobbyGameDB.GetPlayerName(accountId, data => {
            if (data != null)
            {
                Lobby.RPC("ReceivePlayerName", info.sender, accountId, data);
                GameDB.accountIdToName[accountId] = data;
            }
        });
    }
Ejemplo n.º 15
0
    // Account login
    void OnAccountLoggedIn(Account account)
    {
        // Save the reference in a dictionary
        var player = new LobbyPlayer(account);

        // Disconnected already?
        // This can happen if the database takes too much time to respond.
        if (player.disconnected)
        {
            LogManager.General.LogWarning("Peer disconnected already, interrupting login process for: " + player.peer);
            return;
        }

        LogManager.General.Log("Account '" + account.name + "' logged in.");

        // Set online status
        player.onlineStatus = OnlineStatus.Online;

        // Async: Retrieve the player information
        SendPublicAccountInfo(
            player.accountId,                   // Account ID
            player                              // Receiver
            );

        // Others
        SettingsDB.GetInputSettings(player);
        AccessLevelsDB.GetAccessLevel(player);
        FriendsDB.GetFriends(player);
        FriendsDB.GetFollowers(player);

        // Async: Set last login date
        LobbyGameDB.SetLastLoginDate(player, System.DateTime.UtcNow);

        // Register access to this account by this IP
        IPInfoDB.RegisterAccountAccess(player.ip, player.accountId);

        // Save country
        player.UpdateCountry();
    }
Ejemplo n.º 16
0
    // SendInfoAboutOtherAccounts
    void SendInfoAboutOtherAccounts()
    {
        if (friends == null || followers == null)
        {
            return;
        }

        foreach (var friendAccountId in accountsWhereInfoIsRequired)
        {
            string friendName = null;

            // Send name
            if (GameDB.accountIdToName.TryGetValue(friendAccountId, out friendName))
            {
                Lobby.RPC("ReceivePlayerName", peer, friendAccountId, friendName);
            }
            else
            {
                string lambdaAccountId = friendAccountId;

                LobbyGameDB.GetPlayerName(lambdaAccountId, data => {
                    if (data != null)
                    {
                        GameDB.accountIdToName[lambdaAccountId] = data;
                        Lobby.RPC("ReceivePlayerName", this.peer, lambdaAccountId, data);
                    }
                });
            }

            // Send initial online status
            LobbyPlayer player;
            if (accountIdToLobbyPlayer.TryGetValue(friendAccountId, out player))
            {
                Lobby.RPC("ReceiveOnlineStatus", this.peer, friendAccountId, player.onlineStatus);
            }
        }
    }
Ejemplo n.º 17
0
    IEnumerator RemoveFriend(string friendName, string groupName, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        LogManager.General.Log(string.Format("'{0}' removed '{1}' from friend list group '{2}'", player.name, friendName, groupName));

        // Find friends group
        var selectedGroup = player.friends.GetGroupByName(groupName);

        // Get account ID
        string friendAccountId = null;

        yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => {
            friendAccountId = data;
        }));

        // Error getting account ID?
        if (friendAccountId == null)
        {
            Lobby.RPC("FriendRemovePlayerDoesntExistError", info.sender, friendName);
            yield break;
        }

        // Remove player from the group
        selectedGroup.friends.RemoveAll(friend => friend.accountId == friendAccountId);

        // Send new friends list
        player.OnFriendsListLoaded();

        // Save friends list in database
        yield return(FriendsDB.SetFriends(
                         player.accountId,
                         player.friends,
                         null
                         ));
    }
Ejemplo n.º 18
0
    IEnumerator GuildInvitationRequest(string guildId, string playerName, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        // Check if the player has guild invitation rights
        if (!Guild.CanInvite(guildId, player.accountId))
        {
            Lobby.RPC("GuildInvitationError", info.sender, playerName);
            yield break;
        }

        List <string> guildInvitations  = null;
        string        accountIdToInvite = null;

        // Get account ID
        yield return(LobbyGameDB.GetAccountIdByPlayerName(playerName, data => {
            accountIdToInvite = data;
        }));

        if (accountIdToInvite == null)
        {
            Lobby.RPC("GuildInvitationPlayerDoesntExistError", info.sender, playerName);
            yield break;
        }

        // Get guild members
        if (!GameDB.guildIdToGuildMembers.ContainsKey(guildId))
        {
            yield return(GuildsDB.GetGuildMembers(guildId));
        }

        // Already a member?
        var guildMembers = GameDB.guildIdToGuildMembers[guildId];

        if (guildMembers.Find(m => m.accountId == accountIdToInvite) != null)
        {
            Lobby.RPC("GuildInvitationAlreadyMember", info.sender, playerName);
            yield break;
        }

        // Get guild invitations
        if (LobbyPlayer.accountIdToLobbyPlayer.ContainsKey(accountIdToInvite))
        {
            guildInvitations = LobbyPlayer.accountIdToLobbyPlayer[accountIdToInvite].guildInvitations;
        }

        if (guildInvitations == null)
        {
            yield return(GuildsDB.GetGuildInvitations(accountIdToInvite, data => {
                if (data == null)
                {
                    guildInvitations = new List <string>();
                }
                else
                {
                    guildInvitations = data;
                }
            }));
        }

        if (guildInvitations == null)
        {
            Lobby.RPC("GuildInvitationError", info.sender, playerName);
            yield break;
        }

        // Guild invitation already sent?
        if (guildInvitations.Contains(guildId))
        {
            Lobby.RPC("GuildInvitationAlreadySent", info.sender, playerName);
            yield break;
        }

        // Add guild to invitation list
        guildInvitations.Add(guildId);

        // Set guild invitations
        yield return(GuildsDB.SetGuildInvitations(accountIdToInvite, guildInvitations, data => {
            if (data == null)
            {
                Lobby.RPC("GuildInvitationError", info.sender, playerName);
            }
            else
            {
                // Notify player if he is online
                if (LobbyPlayer.accountIdToLobbyPlayer.ContainsKey(accountIdToInvite))
                {
                    var invitedPlayer = LobbyPlayer.accountIdToLobbyPlayer[accountIdToInvite];
                    invitedPlayer.guildInvitations = data;
                    Lobby.RPC("ReceiveGuildInvitationsList", invitedPlayer.peer, invitedPlayer.guildInvitations.ToArray(), true);
                }

                Lobby.RPC("GuildInvitationSuccess", info.sender, playerName);
            }
        }));
    }
    IEnumerator LobbyRegisterAccount(string email, string password, LobbyMessageInfo info)
    {
        // Validate data
        // Password is modified at this point anyway, no need to check it
        if (!Validator.email.IsMatch(email) && !GameDB.IsTestAccount(email))
        {
            yield break;
        }

        // Check if email has already been registered
        bool emailExists = false;

        yield return(LobbyGameDB.GetAccountIdByEmail(email, data => {
            if (data != null)
            {
                emailExists = true;
            }
        }));

        if (emailExists)
        {
            Lobby.RPC("EmailAlreadyExists", info.sender);
            yield break;
        }

        // Register account in uLobby
        var registerReq = AccountManager.Master.RegisterAccount(email, password);

        yield return(registerReq.WaitUntilDone());

        // Bug in uLobby: We need to call this explicitly on the client
        if (!registerReq.isSuccessful)
        {
            var exception = (AccountException)registerReq.exception;
            var error     = exception.error;

            Lobby.RPC("_RPCOnRegisterAccountFailed", info.sender, email, error);
            yield break;
        }

        // Set email for the account
        Account account = registerReq.result;

        yield return(LobbyGameDB.SetEmail(account.id.value, email, data => {
            // ...
        }));

        // Bug in uLobby: We need to call this explicitly on the client
        Lobby.RPC("_RPCOnAccountRegistered", info.sender, account);

        // Log it
        LogManager.General.Log(string.Format(
                                   "[{0}] New account has been registered: E-Mail: '{1}'",
                                   info.sender.endpoint.Address,
                                   email
                                   ));

        // Activation mail
        if (!GameDB.IsTestAccount(email))
        {
            LobbyGameDB.PutAccountAwaitingActivation(
                email,
                (data) => {
                SendActivationMail(email, data);
            }
                );
        }
    }
    IEnumerator LobbyAccountLogIn(string email, string password, string deviceId, LobbyMessageInfo info)
    {
        // Check account activation
        bool activated = false;

        if (!GameDB.IsTestAccount(email))
        {
            yield return(LobbyGameDB.GetAccountAwaitingActivation(
                             email,
                             (data) => {
                if (string.IsNullOrEmpty(data))
                {
                    activated = true;
                }
                else
                {
                    activated = false;
                }
            }
                             ));
        }
        else
        {
            activated = true;
        }

        if (!activated)
        {
            Lobby.RPC("AccountNotActivated", info.sender, email);
            yield break;
        }

        // TODO: Check device ID

        // Login
        LogManager.General.Log("Login attempt: '" + email + "' on device " + deviceId);

        // Get account
        var getAccountReq = AccountManager.Master.TryGetAccount(email);

        yield return(getAccountReq.WaitUntilDone());

        if (getAccountReq.isSuccessful)
        {
            var account = getAccountReq.result;

            // Log out account if logged in from a different peer
            if (account != null && AccountManager.Master.IsLoggedIn(account))
            {
                var peer = AccountManager.Master.GetLoggedInPeer(account);

                LogManager.General.LogWarning(string.Format(
                                                  "Account '{0}' already logged in, kicking old peer: {1}",
                                                  account.name,
                                                  peer
                                                  ));

                var logoutReq = AccountManager.Master.LogOut(peer);
                yield return(logoutReq.WaitUntilDone());
            }
        }

        // Login
        var loginReq = AccountManager.Master.LogIn(info.sender, email, password);

        yield return(loginReq.WaitUntilDone());

        if (!loginReq.isSuccessful)
        {
            var exception = (AccountException)loginReq.exception;
            var error     = exception.error;

            // Bug in uLobby: We need to call this explicitly on the client
            Lobby.RPC("_RPCOnLogInFailed", info.sender, email, error);
            yield break;
        }
    }
Ejemplo n.º 21
0
    // Sends data about the account to any player
    public static void SendPublicAccountInfo(string accountId, LobbyPlayer toPlayer)
    {
        var player = GetLobbyPlayer(accountId);

        // Name
        LobbyGameDB.GetPlayerName(accountId, data => {
            if (data == null)
            {
                if (player == toPlayer)
                {
                    Lobby.RPC("AskPlayerName", toPlayer.peer);
                }
            }
            else
            {
                Lobby.RPC("ReceivePlayerName", toPlayer.peer, accountId, data);

                if (player == toPlayer)
                {
                    if (string.IsNullOrEmpty(player.name))
                    {
                        player.name = data;
                        LobbyServer.OnReceivePlayerName(player);
                    }
                }
            }
        });

        // Character customization
        CharacterCustomizationDB.GetCharacterCustomization(accountId, data => {
            if (data == null)
            {
                if (player == toPlayer)
                {
                    Lobby.RPC("CustomizeCharacter", toPlayer.peer, accountId);
                }
            }
            else
            {
                if (player != null)
                {
                    player.custom = data;
                }
                Lobby.RPC("ReceiveCharacterCustomization", toPlayer.peer, accountId, data);
            }
        });

        // Skill build
        SkillBuildsDB.GetSkillBuild(accountId, data => {
            if (data == null)
            {
                Lobby.RPC("ReceiveSkillBuild", toPlayer.peer, accountId, SkillBuild.GetStarterBuild());
            }
            else
            {
                Lobby.RPC("ReceiveSkillBuild", toPlayer.peer, accountId, data);
            }
        });

        // Stats
        LobbyGameDB.GetPlayerStats(accountId, data => {
            if (data == null)
            {
                data = new PlayerStats();
            }

            // Assign stats
            if (player != null)
            {
                player.stats = data;
            }

            // Send the stats to the player
            Lobby.RPC("ReceivePlayerStats", toPlayer.peer,
                      accountId,
                      Jboy.Json.WriteObject(data)
                      );
        });

        // FFA Stats
        LobbyGameDB.GetPlayerFFAStats(accountId, data => {
            if (data == null)
            {
                data = new PlayerStats();
            }

            // Assign stats
            if (player != null)
            {
                player.ffaStats = data;
            }

            // Send the stats to the player
            Lobby.RPC("ReceivePlayerFFAStats", toPlayer.peer,
                      accountId,
                      Jboy.Json.WriteObject(data)
                      );
        });

        // Character stats
        TraitsDB.GetCharacterStats(accountId, data => {
            if (data == null)
            {
                data = new CharacterStats();
            }

            if (player != null)
            {
                player.charStats = data;
            }

            Lobby.RPC("ReceiveCharacterStats", toPlayer.peer, accountId, data);
        });

        // Artifact inventory
        ArtifactsDB.GetArtifactInventory(accountId, data => {
            if (data == null)
            {
                data = new ArtifactInventory();
            }

            if (player != null)
            {
                player.artifactInventory = data;
            }

            Lobby.RPC("ReceiveArtifactInventory", toPlayer.peer, accountId, Jboy.Json.WriteObject(data));
        });

        // Artifact tree
        ArtifactsDB.GetArtifactTree(accountId, data => {
            if (data == null)
            {
                data = ArtifactTree.GetStarterArtifactTree();
            }

            if (player != null)
            {
                player.artifactTree = data;
            }

            Lobby.RPC("ReceiveArtifactTree", toPlayer.peer, accountId, Jboy.Json.WriteObject(data));
        });

        // Experience
        ExperienceDB.GetExperience(accountId, data => {
            uint exp = 0;

            if (data != null)
            {
                exp = data.experience;
            }

            Lobby.RPC("ReceiveExperience", toPlayer.peer, accountId, exp);
        });

        // Item inventory
        ItemInventoryDB.GetItemInventory(accountId, data => {
            if (data == null)
            {
                data = new ItemInventory();
            }

            if (player != null)
            {
                player.itemInventory = data;
            }

            Lobby.RPC("ReceiveItemInventory", toPlayer.peer, accountId, Jboy.Json.WriteObject(data));
        });

        // View profile
        Lobby.RPC("ViewProfile", toPlayer.peer, accountId);
    }
Ejemplo n.º 22
0
    // Start
    void Start()
    {
        // Player
        playerCommands = new ChatCommand <LobbyPlayer>[] {
            // practice
            new ChatCommand <LobbyPlayer>(
                @"^practice$",
                (player, args) => {
                if (!player.inMatch)
                {
                    LobbyQueue.CreatePracticeMatch(player);
                }
                else
                {
                    // Notify player ...
                }
            }
                ),

            // online
            new ChatCommand <LobbyPlayer>(
                @"^online$",
                (player, args) => {
                LobbyServer.SendSystemMessage(player, "Players online: " + LobbyPlayer.list.Count);
            }
                )
        };

        // VIP
        vipCommands = new ChatCommand <LobbyPlayer>[] {
            // list
            new ChatCommand <LobbyPlayer>(
                @"^list$",
                (player, args) => {
                LobbyServer.SendSystemMessage(player, "Town: " + LobbyTown.running.Count);
                LobbyServer.SendSystemMessage(player, "World: " + LobbyWorld.running.Count);
                LobbyServer.SendSystemMessage(player, "Arena: " + LobbyMatch.running.Count);
                LobbyServer.SendSystemMessage(player, "FFA: " + LobbyFFA.running.Count);
            }
                )
        };

        // Community Manager
        communityManagerCommands = new ChatCommand <LobbyPlayer>[] {
            // goto
            new ChatCommand <LobbyPlayer>(
                @"^goto ([^ ]+) (.*)$",
                (player, args) => {
                var serverType = ChatServer.GetServerType(args[0]);
                var mapName    = args[1];

                player.location = new PlayerLocation(mapName, serverType);
            }
                ),

            // moveToPlayer
            new ChatCommand <LobbyPlayer>(
                @"^moveToPlayer (.*)$",
                (player, args) => {
                var playerName = args[1];

                LobbyGameDB.GetAccountIdByPlayerName(playerName, accountId => {
                    if (accountId == null)
                    {
                        return;
                    }

                    PositionsDB.GetPosition(accountId, position => {
                        if (position == null)
                        {
                            position = new PlayerPosition();
                        }

                        LocationsDB.GetLocation(accountId, location => {
                            if (location == null)
                            {
                                return;
                            }

                            // TODO: This is not 100% correct as it might get overwritten by the server
                            PositionsDB.SetPosition(player.accountId, position);

                            player.location = location;
                        });
                    });
                });
            }
                ),
        };

        // Game Master
        gameMasterCommands = new ChatCommand <LobbyPlayer>[] {
            // start
            new ChatCommand <LobbyPlayer>(
                @"^start ([^ ]+) (.*)$",
                (player, args) => {
                var serverType = ChatServer.GetServerType(args[0]);
                var mapName    = args[1];

                switch (serverType)
                {
                case ServerType.FFA:
                    new LobbyFFA(mapName).Register();
                    break;

                case ServerType.Town:
                    new LobbyTown(mapName).Register();
                    break;
                }
            }
                ),
        };

        // Admin
        adminCommands = new ChatCommand <LobbyPlayer>[] {
        };

        // Make this class listen to lobby events
        Lobby.AddListener(this);
    }