Exemplo n.º 1
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
                         ));
    }
Exemplo n.º 2
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);
            }
        }));
    }
Exemplo n.º 3
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);
         }
     }));
 }
Exemplo n.º 4
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
                         ));
    }
Exemplo n.º 5
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);
            }
        }));
    }
Exemplo n.º 6
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
                         ));
    }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
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);
            }
        }));
    }