예제 #1
0
    IEnumerator GuildInvitationsListRequest(LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        // Get guild invitations
        if (player.guildInvitations == null)
        {
            yield return(GuildsDB.GetGuildInvitations(player.accountId, data => {
                if (data == null)
                {
                    player.guildInvitations = new List <string>();
                }
                else
                {
                    player.guildInvitations = data;
                }
            }));
        }

        Lobby.RPC("ReceiveGuildInvitationsList", player.peer, player.guildInvitations.ToArray(), true);
    }
예제 #2
0
    IEnumerator GuildInvitationResponse(string guildId, bool accepted, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        // Get guild invitations
        if (player.guildInvitations == null)
        {
            yield return(GuildsDB.GetGuildInvitations(player.accountId, data => {
                if (data == null)
                {
                    player.guildInvitations = new List <string>();
                }
                else
                {
                    player.guildInvitations = data;
                }
            }));
        }

        if (player.guildInvitations == null)
        {
            Lobby.RPC("GuildInvitationResponseError", info.sender, guildId);
            yield break;
        }

        // Were you invited?
        if (!player.guildInvitations.Contains(guildId))
        {
            Lobby.RPC("GuildInvitationResponseError", info.sender, guildId);
            yield break;
        }

        // Did the player accept the invitation?
        if (accepted)
        {
            // Get guild members from database
            if (!GameDB.guildIdToGuildMembers.ContainsKey(guildId))
            {
                yield return(GuildsDB.GetGuildMembers(guildId));
            }

            var guildMembers = GameDB.guildIdToGuildMembers[guildId];
            guildMembers.Add(new GuildMember(player.accountId, player.name, (byte)GuildMember.Rank.Default));

            // Set guild members
            yield return(GuildsDB.SetGuildMembers(guildId, guildMembers));

            // Get guild ID list
            if (player.guildList == null)
            {
                yield return(GuildsDB.GetGuildList(player.accountId, data => {
                    if (data == null)
                    {
                        player.guildList = new GuildList();
                    }
                    else
                    {
                        player.guildList = data;
                    }
                }));
            }

            // Add to guild ID list
            player.guildList.Add(guildId);

            // Set guild ID list
            yield return(GuildsDB.SetGuildList(player.accountId, player.guildList));

            // Notify all guild members
            SendGuildMemberList(guildId, guildMembers);
        }

        // Remove guild from invitation list
        player.guildInvitations.Remove(guildId);

        // Set guild invitations
        yield return(GuildsDB.SetGuildInvitations(player.accountId, player.guildInvitations, data => {
            if (data == null)
            {
                Lobby.RPC("GuildInvitationResponseError", info.sender, guildId);
            }
            else
            {
                player.guildInvitations = data;
                Lobby.RPC("GuildInvitationResponseSuccess", info.sender, guildId, accepted);
                SendGuildList(player);
            }
        }));
    }
예제 #3
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);
            }
        }));
    }