예제 #1
0
        public override async Task <FriendRequestResult> SendFriendRequest(FriendRequestAttempt request, ServerCallContext context)
        {
            var result = new FriendRequestResult
            {
                IsNowPending = false,
            };

            Player player;

            try
            {
                player = auth.GetPlayer(context);
                if (player == null)
                {
                    return(await Task.FromResult(result));
                }
            } catch (Exception e)
            {
                Log.Exception(e);
                return(await Task.FromResult(result));
            }

            try
            {
                return(await await in_memory_worker.Schedule(async() =>
                {
                    if (player.friends.Count > config.MaxFriendSize)
                    {
                        return result;
                    }

                    var pfr = player.pending_friend_requests_outgoing;
                    if (pfr.Count > config.MaxFriendRequestSize)
                    {
                        return result;
                    }

                    var target_player_permanent_id = request.PlayerId;
                    if (player.HasRequestedPlayerAlready(target_player_permanent_id))
                    {
                        result.IsNowPending = true;
                        return result;
                    }

                    //NOTE: If the target player is ignoring player then this friend request should not go through

                    var success = await auth.SendFriendRequest(player, target_player_permanent_id);
                    if (!success)
                    {
                        return result;
                    }
                    result.IsNowPending = true;
                    return result;
                }));
            } catch (Exception e)
            {
                Log.Exception(e);
                return(await Task.FromResult(result));
            }
        }
        private void ShowFriendRequest(string friendToAdd, Texture avatar)
        {
            if (avatar == null)
            {
                avatar = ImageFriend;
            }
            Show(avatar, FRIEND_REQUEST_TITLE, friendToAdd,
                 () =>
            {
                FriendRequestResult result = new FriendRequestResult
                {
                    FriendToAdd        = friendToAdd,
                    FriendshipAccepted = true
                };
                ConnectionHandler.Instance.SendWebsocketMessage(new WrapperMessage {
                    FriendRequestResult = result
                });

                ChatController.Instance.AddFriend(friendToAdd);
            },
                 () =>
            {
                FriendRequestResult result = new FriendRequestResult
                {
                    FriendToAdd        = friendToAdd,
                    FriendshipAccepted = false
                };
                ConnectionHandler.Instance.SendWebsocketMessage(new WrapperMessage {
                    FriendRequestResult = result
                });
            });
        }
예제 #3
0
 private void OnFriendRequestResult(FriendRequestResult message)
 {
     if (message.FriendshipAccepted)
     {
         AddFriend(message.FriendToAdd);
     }
 }
예제 #4
0
 private static void on_send_friend_request(BasicPlayerInfo target, FriendRequestResult r)
 {
     if (r.IsNowPending)
     {
         if (BasicPlayerInfoOps.Contains(pending_friends_outgoing, target))
         {
             Debug.LogError("Server added pending outgoing friend but the datastore thinks the player is already in the pending list.");
             return;
         }
         pending_friends_outgoing.Add(target);
     }
 }
예제 #5
0
        private void DataFromServer(object?sender, MessageEventArgs e)
        {
            if (e.IsPing)
            {
                return;
            }
            IncomingWSS?data = JsonSerializer.Deserialize(e.Data, IncomingWSSContext.Default.IncomingWSS);

            switch (data?.type)
            {
            case DataType.Login:
                Token = data.token;
                break;

            case DataType.Error:
                if (Token is null)
                {
                    Error = data.error;
                }
                else
                {
                    if (OnError is not null)
                    {
                        _ = OnError.Invoke(new Exception(data.error));
                    }
                }
                break;

            case DataType.Message_Create:
                if (MessageReceived is not null)
                {
                    string?obj = data?.data.ToString();
                    if (obj is not null)
                    {
                        SocketMessage?m = JsonSerializer.Deserialize <SocketMessage>(obj);
                        if (m is not null)
                        {
                            m.decrypt(Encryption.File.Channels.GetKey(m.channel_id));
                            _ = MessageReceived.Invoke(m);
                        }
                    }
                }
                break;

            case DataType.Status_Update:
                if (UserStatusUpdate is not null)
                {
                    string?obj = data?.data.ToString();
                    if (obj is not null)
                    {
                        StatusUpdate?SU = JsonSerializer.Deserialize <StatusUpdate>(obj);
                        if (SU is not null)
                        {
                            SocketRemoteUser after = SocketRemoteUser.GetUser(SU.id);
                            after.status = SU.after;
                            SocketRemoteUser before = (SocketRemoteUser)after.Clone();
                            before.status = SU.before;
                            _             = UserStatusUpdate.Invoke(before, after);
                        }
                    }
                }
                break;

            case DataType.Friend_Request:
                if (ReceivedFriendRequest is not null)
                {
                    string?obj = data?.data.ToString();
                    if (obj is not null)
                    {
                        FriendRequest?request = JsonSerializer.Deserialize <FriendRequest>(obj);
                        if (request is not null)
                        {
                            _ = ReceivedFriendRequest.Invoke(SocketRemoteUser.GetUser(request.id));
                        }
                    }
                }
                break;

            case DataType.Friend_Request_Result:
                if (FriendRequestResult is not null)
                {
                    string?obj = data?.data.ToString();
                    if (obj is not null)
                    {
                        FriendRequestResult?FRR = JsonSerializer.Deserialize <FriendRequestResult>(obj);
                        if (FRR is not null && FRR.channel is not null && FRR.id is not null && FRR.result is not null)
                        {
                            SocketChannel chan = SocketChannel.GetChannel((long)FRR.channel);
                            chans.Add(chan);
                            SocketRemoteUser from1 = SocketRemoteUser.GetUser((long)FRR.id);
                            from1.Channel = chan;
                            _             = FriendRequestResult.Invoke(from1, (bool)FRR.result);
                        }
                    }
                }
                break;

            case DataType.Call_Info:
                if (IncommingCall is not null)
                {
                    string?obj = data?.data.ToString();
                    if (obj is not null)
                    {
                        callinfoinc?ci = JsonSerializer.Deserialize <callinfoinc>(obj);
                        if (ci is not null)
                        {
                            _ = IncommingCall.Invoke(SocketChannel.GetChannel(ci.channel), SocketRemoteUser.GetUser(ci.from));
                        }
                    }
                }
                break;

            case DataType.Call_Data:
                if (AudioClient is not null)
                {
                    AudioClient.Givedata(data.data);
                }
                break;

            case DataType.Key_Exchange:
                try
                {
                    string?obj = data?.data.ToString();
                    if (obj is not null)
                    {
                        KeyExchange?KE = JsonSerializer.Deserialize <KeyExchange>(obj);
                        if (KE is not null)
                        {
                            Encryption.File.Channels.AddKey(KE.channel, Encryption.Encoder.GetString(Encryption.Decrypt(Convert.FromBase64String(KE.key))));
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (OnError is not null)
                    {
                        OnError.Invoke(ex);
                    }
                }
                break;

            default:
                break;
            }
        }