Exemple #1
0
 /// <summary>
 /// 重置属性
 /// </summary>
 public void InitialProperties()
 {
     groupDesc = "";
     groupName = "";
     SelectedMember.Clear();//清空列表
     FriendList.Clear();
     EnableCreate = true;
     Snackbar     = new SnackbarMessageQueue();
     Task.Run(() =>
     {
         Task.Delay(100);
         var friends = new DataOfFriends().GetFriendsList();
         //填充好友列表
         App.Current.Dispatcher.Invoke(() =>
         {
             foreach (var item in friends)
             {
                 if (item.toUserId == "10000")
                 {
                     continue;
                 }
                 FriendList.Add(item.ToMsgListItem());
             }
         });
     });
 }
Exemple #2
0
        public void RPC_GetTopAndFriend(ulong roleId, ushort planesId, Iocp.NetConnection connect, RPC.RPCForwardInfo fwd)
        {
            RPC.PackageWriter pkg = new RPC.PackageWriter();
            TopList.Clear();
            FriendList.Clear();
            var role = this.GetRole(roleId);

            if (role == null)
            {
                Log.Log.Server.Print("RPC_GetTopAndFriend role is null , {0}", roleId);
                pkg.Write((sbyte)-1);
                pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
                return;
            }
            pkg.Write((sbyte)1);
            InitVisitTimes(role);
            pkg.Write(role.RoleData.WorldVisitCount);
            pkg.Write(role.RoleData.FriendVisitCount);
            pkg.Write(role.RoleData.BuyVisitCount);
            pkg.Write(role.RoleData.ByVisitCount);
            List <RankData> rds = _GetFightTopPlayer(planesId);

            pkg.Write((byte)rds.Count);
            foreach (var i in rds)
            {
                pkg.Write(i.RoleId);
                pkg.Write(i.RoleName);
                if (role.VisitTopList.Contains(i.RoleId))
                {
                    pkg.Write((byte)CSCommon.eBoolState.True);
                }
                else
                {
                    pkg.Write((byte)CSCommon.eBoolState.False);
                }
                TopList.Add(i.RoleId);
            }
            UpdateSocialInfoList(CSCommon.eSocialType.Friend, role);
            pkg.Write((byte)role.mSocialInfoList.Count);
            foreach (var j in role.mSocialInfoList.Values)
            {
                pkg.Write(j.id);
                pkg.Write(j.name);
                if (role.VisitFriendList.Contains(j.id))
                {
                    pkg.Write((byte)CSCommon.eBoolState.True);
                }
                else
                {
                    pkg.Write((byte)CSCommon.eBoolState.False);
                }
                FriendList.Add(j.id);
            }
            pkg.DoReturnCommand2(connect, fwd.ReturnSerialId);
        }
        /// <summary>
        /// 异步的加载好友信息
        /// </summary>
        private async Task LoadFriendAsync()
        {
            await ClientHelper.WaitAsync(() => RequestResultAction == null, -1);

            RequestResultAction = new Action <RequestResult>((RequestResult result) =>
            {
                User[] users = result.Object as User[];
                if (users == null)
                {
                    return;
                }

                Home.HomeWindow.Dispatcher.Invoke(() =>
                {
                    var messageRecord = CopyMessageRecord();
                    MessageRecord.Clear();
                    FriendList.Clear();

                    foreach (var user in users)
                    {
                        FriendList.Add(_dataService.GetUserModel(user));
                        MessageRecord.Add(user.UserName, new List <MessageModel>());
                        if (messageRecord.ContainsKey(user.UserName))
                        {
                            foreach (var messageModel in messageRecord[user.UserName])
                            {
                                MessageRecord[user.UserName].Add(messageModel);
                            }
                        }
                    }
                });
            });

            if (!Config.MiniClient.SendDatabaseRequest(new User()
            {
                UserName = UserModel.UserName
            }, "GetFriends", null))
            {
                RequestResultAction = null;
                MessageBox.Show("加载好友数据时发生错误!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Receive()
        {
            bool already_check = true;

            while (connected)
            {
                try
                {
                    Byte[] buffer = new Byte[128];
                    clientSocket.Receive(buffer);

                    string incomingMessage = Encoding.Default.GetString(buffer);
                    incomingMessage = incomingMessage.Substring(0, incomingMessage.IndexOf("\0"));
                    //logs.AppendText("Message received" + "\n");
                    //logs.AppendText("Server: " + incomingMessage + "\n");
                    if (incomingMessage == "EfeYarenYigitKayaYou successfully logged inEfeYarenYigitKaya")
                    {
                        textBox_message.Enabled = true;   //after successfully connection, textbox button should be active.
                        send_button.Enabled     = true;   //after connection, send button should be active.
                        logs.AppendText("Connected to the server!\n");
                        disconnect_button.Enabled = true; //after connected disconnect button should be active.
                        userName = incomingName;
                        connect_button.Enabled = false;   //already connected so connect button shoul be inactive
                        AcceptBut.Enabled      = true;
                        RejectBut.Enabled      = true;
                        friendsBut.Enabled     = true;
                        sendReqBut.Enabled     = true;
                        button1.Enabled        = true;
                        deleteButton.Enabled   = true;
                    }
                    else if (incomingMessage == "EfeYarenYigitKayaThis username does not exist in databaseEfeYarenYigitKaya") //server sends does not exist message
                    {
                        logs.AppendText("You are not in the database\n");                                                     //if this message came from the server and username was wrong, print this
                    }
                    else if (incomingMessage == "EfeYarenYigitKayaYou are already logged inEfeYarenYigitKaya")
                    {
                        logs.AppendText("You already logged in\n"); //correct username but it already connected
                        already_check = false;                      //for blocked to another connection from same user
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 18) == "EfeYarenYigitKaya£")
                    {
                        string inviter = incomingMessage.Substring(18, incomingMessage.Length - 18);
                        if (!requestList.Contains(inviter))
                        {
                            requestList.Add(inviter); // yeni ekledim whenever you receive request that does not exist in your request list add it to your list
                        }
                        friendReqList.Clear();
                        //requestList.Add(inviter);
                        //bool flag = true;
                        string currentRequest = "";
                        foreach (string name in requestList)
                        {
                            currentRequest += name + "\n";
                        }
                        friendReqList.AppendText(currentRequest);
                        //    if(name == inviter)
                        //    {
                        //        flag = false;
                        //    }
                        //}
                        //if (flag)
                        //{
                        //    requestList.Add(inviter);
                        //    currentRequest += inviter;
                        //}
                        //friendReqList.AppendText(currentRequest + "\n");
                        //friendReqList.AppendText(inviter + "\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 19) == "EfeYarenYigitKaya*£")
                    {
                        string myMessage = incomingMessage.Substring(19, incomingMessage.Length - 19);
                        logs.AppendText(myMessage + "\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 19) == "EfeYarenYigitKaya*!")
                    {
                        int    index     = incomingMessage.IndexOf("%");
                        string sender    = incomingMessage.Substring(19, index - 19);
                        string myMessage = incomingMessage.Substring(index + 1);
                        logs.AppendText(sender + ": " + myMessage + "\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 20) == "EfeYarenYigitKaya*<f")
                    {
                        string deletedfriend = incomingMessage.Substring(20);
                        logs.AppendText("There is no such friend as " + deletedfriend + " in your friends list\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 20) == "EfeYarenYigitKaya*<s")
                    {
                        string deletedfriend = incomingMessage.Substring(20);
                        logs.AppendText("You have succesfully remove " + deletedfriend + " from your friends list\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 19) == "EfeYarenYigitKaya*<")
                    {
                        string clientName = incomingMessage.Substring(19);
                        logs.AppendText(clientName + " removed you from friends\n");
                    }

                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 18) == "EfeYarenYigitKaya#") // once accept friend request
                    {
                        string invitee = incomingMessage.Substring(18, incomingMessage.Length - 18);
                        //friendReqList.AppendText(invitee + "\n");
                        logs.AppendText(invitee + " Accepted your friend request\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 18) == "EfeYarenYigitKaya&")
                    {
                        string invitee = incomingMessage.Substring(18, incomingMessage.Length - 18);
                        friendReqList.AppendText(invitee + "\n");
                    }
                    else if (incomingMessage.Length > 18 && incomingMessage.Substring(0, 19) == "EfeYarenYigitKaya*&")
                    {
                        string invitee = incomingMessage.Substring(19, incomingMessage.Length - 19);
                        logs.AppendText(invitee + "\n");
                    }

                    else if (incomingMessage.Length > 17 && incomingMessage.Substring(0, 18) == "EfeYarenYigitKaya$") // receive friends from server
                    {
                        //FriendList.AppendText("print friend list");
                        FriendList.Clear();
                        string friends = incomingMessage.Substring(18, incomingMessage.Length - 18);
                        friends = friends.Replace(',', '\n');
                        FriendList.AppendText(friends);
                        //if(friends.Length > 1)
                        //FriendList.AppendText("********\n");
                    }
                    else if (incomingMessage.Substring(0, 3) == "123")
                    {
                        logs.AppendText(incomingMessage.Substring(3)); // you have already requested and wait for answer
                    }
                    else if (incomingMessage.Substring(0, 3) == "321")
                    {
                        logs.AppendText(incomingMessage.Substring(3)); // you requested but there is no such user in database
                    }
                    else
                    {
                        incomingMessage = incomingMessage.Substring(17, incomingMessage.Length - 34); //true connection and message
                        logs.AppendText(incomingMessage + "\n");                                      //print the incoming message
                    }
                }
                catch (Exception e)
                {
                    //FriendList.AppendText(e.Message);
                    if (!terminating)
                    {
                        if (already_check)
                        {
                            logs.AppendText("The server has disconnected\n"); //disconnect button activated
                        }
                        server_check            = false;
                        already_check           = true;  // user can enter again
                        connect_button.Enabled  = true;  //user can connect again because disconnect now
                        textBox_message.Enabled = false; //user cannot write text
                        send_button.Enabled     = false; //user cannot send message
                    }

                    clientSocket.Close();
                    connected = false;
                }
            }
        }