Ejemplo n.º 1
0
        // xóa user khỏi online list
        public static void UserOffline()
        {
            if (onlineList.Count == 0)
            {
                return;
            }

            for (int i = 0; i < onlineList.Count; i++)
            {
                Online userOnline = onlineList[i];
                if (!isConnected(userOnline.userClient))
                {
                    Console.WriteLine("User " + userOnline.user_id + " offline");

                    DataBase.ChangeStatusUser(userOnline.user_id);
                    DataBase.ChangeStatusFriendList(userOnline.user_id);

                    // xử lý khi người chơi disconnect trong room
                    RemoveUserFromRoom(userOnline.user_id);

                    // xóa object
                    onlineList.Remove(userOnline);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Invite(string user_id, string friend_id, string user_avatar, TcpClient userClient)
        {
            for (int i = 0; i < roomList.Count; i++)
            {
                Room room = roomList[i];
                if (room.join_id.Equals(friend_id))
                {
                    Server.SendData("youhostduel:busy:", userClient);
                    return;
                }
            }

            for (int i = 0; i < onlineList.Count; i++)
            {
                Online friend = onlineList[i];
                if (friend.user_id.Equals(friend_id))
                {
                    Random random  = new Random();
                    string room_no = Convert.ToString(random.Next(1, 999999));

                    RoomDuel roomDuel = new RoomDuel
                    {
                        host_id    = user_id,
                        join_id    = friend_id,
                        hostClient = userClient,
                        joinClient = friend.userClient,
                        room_no    = room_no
                    };


                    Room room = new Room
                    {
                        host_id     = user_id,
                        host_avatar = user_avatar,
                        hostClient  = userClient,
                        room_no     = room_no,
                        room_key    = roomDuel.room_key
                    };


                    // thêm vào danh sách room
                    roomList.Add(room);
                    roomDuelList.Add(roomDuel);

                    // gửi thông tin cho phép user tạo phòng chiến với bạn
                    Server.SendData("youhostduel:true:" + room_no, userClient);

                    // gửi thông tin lời mời cho friend
                    Server.SendData("invitetoduel:" + user_id + ":" + room_no, friend.userClient);

                    // lưu room vào db
                    DataBase.TaoRoom(user_id, room_no, roomDuel.room_key);

                    break;
                }
            }
        }
Ejemplo n.º 3
0
        // thêm user vào online list
        public static void UserOnline(string user_id, TcpClient userClient)
        {
            Online userOnline = new Online
            {
                user_id    = user_id,
                userClient = userClient
            };

            // thêm user vào online list
            onlineList.Add(userOnline);

            Console.WriteLine("User " + user_id + " online");
        }
Ejemplo n.º 4
0
        public static void UserOffline(string offline_user)
        {
            // xóa object
            for (int i = 0; i < onlineList.Count; i++)
            {
                Online user = onlineList[i];
                if (user.user_id.Equals(offline_user))
                {
                    Console.WriteLine("User " + user.user_id + " offline");

                    DataBase.ChangeStatusUser(user.user_id);
                    DataBase.ChangeStatusFriendList(user.user_id);

                    onlineList.Remove(user);
                    break;
                }
            }
        }