Beispiel #1
0
        public void InviteTimeoutCallback(RemoteCall callInfo)
        {
            // if the call timed out the character is not connected
            InviteExtraInfo call = callInfo.ExtraInfo as InviteExtraInfo;

            call.OriginalCall.Client.SendException(
                call.OriginalCall,
                new ChtCharNotReachable(this.CharacterDB.GetCharacterName(call.ToCharacterID))
                );
        }
Beispiel #2
0
        public void InviteAnswerCallback(RemoteCall callInfo, PyDataType result)
        {
            InviteExtraInfo call = callInfo.ExtraInfo as InviteExtraInfo;

            if (result is PyString answer)
            {
                // this user's character might not be in the service
                // so fetch the name from the database
                call.OriginalCall.Client.SendException(
                    call.OriginalCall,
                    new UserError(
                        answer,
                        new PyDictionary
                {
                    ["channel"] = this.DB.GetChannelName(call.ChannelID),
                    ["char"]    = this.CharacterDB.GetCharacterName(call.ToCharacterID)
                }
                        )
                    );
            }

            // return an empty response to the original calling client, this should get mechanism going for the JoinChannel notification
            call.OriginalCall.Client.SendCallResponse(call.OriginalCall, null);

            // character has accepted, notify all users of the channel
            string channelType = this.DB.GetChannelType(call.ChannelID);

            PyDataType notification =
                GenerateLSCNotification("JoinChannel", call.ChannelID, new PyTuple(0), callInfo.Client);

            // you should only be able to invite to global channels as of now
            // TODO: CORP CHANNELS SHOULD BE SUPPORTED TOO
            if (channelType == ChatDB.CHANNEL_TYPE_NORMAL)
            {
                // get users in the channel that are online now
                PyList characters = this.DB.GetOnlineCharsOnChannel(call.ChannelID);

                // notify them all
                call.OriginalCall.Client.ClusterConnection.SendNotification("OnLSC", "charid", characters, notification);
            }
        }
Beispiel #3
0
        public PyDataType Invite(PyInteger characterID, PyInteger channelID, PyString channelTitle, PyBool addAllowed, CallInformation call)
        {
            int callerCharacterID = call.Client.EnsureCharacterIsSelected();

            try
            {
                if (characterID == callerCharacterID)
                {
                    throw new ChtCannotInviteSelf();
                }

                if (ItemManager.IsNPC(characterID) == true)
                {
                    // NPCs should be loaded, so the character instance can be used willy-nilly
                    Character npcChar = this.ItemManager.GetItem(characterID) as Character;

                    throw new ChtNPC(npcChar.Name);
                }

                // ensure our character has admin perms first
                if (this.DB.IsCharacterOperatorOrAdminOfChannel(channelID, callerCharacterID) == false)
                {
                    throw new ChtWrongRole(this.DB.GetChannelName(channelID), "Operator");
                }

                // ensure the character is not there already
                if (this.DB.IsCharacterMemberOfChannel(channelID, characterID) == true)
                {
                    throw new ChtAlreadyInChannel(this.CharacterDB.GetCharacterName(characterID));
                }

                Character character = this.ItemManager.GetItem(callerCharacterID) as Character;

                PyTuple args = new PyTuple(4)
                {
                    [0] = callerCharacterID,
                    [1] = character.Name,
                    [2] = character.Gender,
                    [3] = channelID
                };

                InviteExtraInfo info = new InviteExtraInfo
                {
                    OriginalCall    = call,
                    Arguments       = args,
                    ChannelID       = channelID,
                    ToCharacterID   = characterID,
                    FromCharacterID = callerCharacterID
                };

                // no timeout for this call
                call.Client.ClusterConnection.SendServiceCall(
                    characterID,
                    "LSC", "ChatInvite", args, new PyDictionary(),
                    InviteAnswerCallback, InviteTimeoutCallback,
                    info, ProvisionalResponse.DEFAULT_TIMEOUT - 5
                    );

                // subscribe the user to the chat
                this.DB.JoinChannel(channelID, characterID);
            }
            catch (ArgumentOutOfRangeException)
            {
                Log.Warning("Trying to invite a non-online character, aborting...");
            }

            // return SOMETHING to the client with the provisional data
            // the real answer will come later on
            throw new ProvisionalResponse(new PyString("OnDummy"), new PyTuple(0));
        }