Example #1
0
        private void ConfirmJoinToRoom(IPackage package)
        {
            IConfirmJoinToRoom confirmJoinData = package.Data as IConfirmJoinToRoom;

            ManagerRoom = Owner as IManagerRoom;

            var client_passport = package.Sender_Passport;

            IGamer gamer = ManagerRoom.GetGamerByGuid(client_passport);

            var room_passport = confirmJoinData.RoomPassport;
            var room          = ManagerRoom.GetRoomByGuid(room_passport);

            if (room != null)
            {
                if (room.Gamers.Count() < room.GameSetings.MaxPlayersCount)
                {
                    ManagerRoom.MooveGamerToRoom(gamer, room_passport);

                    //(room as IGameRoom).NotifyGameRoomForEvent(new NotifyJoinedPlayerData() { JoinedAddresssee = gamer });

                    //// инициировать начало игры
                    //if (room.Gamers.Count() == room.GameSetings.MaxPlayersCount)
                    //{
                    //    IPackage pack = new Package()
                    //    {
                    //        MesseggeType = MesseggeType.StartGame,
                    //        Data = null,
                    //    };
                    //    Owner.Sender.SendMessage(pack, room.Gamers); //Управляющая комната отсылает участникам игровой комнаты

                    //    //уведомляем игровую комнату о начале:
                    //    (room as IGameRoom).NotifyGameRoomForEvent(new NotifyStartGameData() { EnforceStartGame = true });
                    //}
                }
                else
                {
                    Owner.Sender.SendMessage(new Package()
                    {
                        Data         = "Room is full",
                        MesseggeType = MesseggeType.Error
                    }, gamer.RemoteEndPoint);
                }
            }
            else
            {
                Owner.Sender.SendMessage(new Package()
                {
                    Data         = "Room is not exist",
                    MesseggeType = MesseggeType.Error
                }, gamer.RemoteEndPoint);
            }
        }
Example #2
0
        private void RoomConnect(IPackage package)
        {
            ManagerRoom = Owner as IManagerRoom;

            var cd              = (IConectionData)package.Data;
            var name            = cd.PlayerName;
            var client_passport = package.Sender_Passport;

            IGamer gamer = ManagerRoom.GetGamerByGuid(client_passport);

            gamer.SetId(name, client_passport);
            var room_passport = cd.RoomPasport;

            var room     = ManagerRoom.GetRoomByGuid(room_passport);
            var map_Size = room.GameSetings.MapSize;

            if (room != null)
            {
                if (room.Gamers.Count() < room.GameSetings.MaxPlayersCount)
                {
                    //IPEndPoint room_ipendpoint = ManagerRoom.MooveGamerToRoom(gamer, room_passport); - Это будет делаться по отдельному сообщению ConfirmJoinToRoom
                    IPEndPoint room_ipendpoint = room.Reciever.LockalEndPoint;
                    Addresssee addres          = new Addresssee(room_ipendpoint);

                    var roominfo = new RoomInfo()
                    {
                        RoomPassport = room_passport,
                        roomEndpoint = addres,
                        mapSize      = map_Size
                    };

                    Owner.Sender.SendMessage(new Package()
                    {
                        Data         = roominfo,
                        MesseggeType = MesseggeType.RoomInfo
                    }, gamer);                       //gamer.RemoteEndPoint

                    // Это будет делаться по отдельному сообщению ConfirmJoinToRoom
                    //(room as IGameRoom).NotifyGameRoomForEvent(new NotifyJoinedPlayerData() { JoinedAddresssee = gamer });

                    //// инициировать начало игры
                    //if (room.Gamers.Count() == room.GameSetings.MaxPlayersCount)
                    //{
                    //    IPackage pack = new Package()
                    //    {
                    //        MesseggeType = MesseggeType.StartGame,
                    //        Data = null,
                    //    };
                    //    Owner.Sender.SendMessage(pack, room.Gamers); //Управляющая комната отсылает участникам игровой комнаты

                    //    //уведомляем игровую комнату о начале:
                    //    (room as IGameRoom).NotifyGameRoomForEvent(new NotifyStartGameData() { EnforceStartGame = true });
                    //}
                }
                else
                {
                    Owner.Sender.SendMessage(new Package()
                    {
                        Data         = "Room is full",
                        MesseggeType = MesseggeType.Error
                    }, gamer.RemoteEndPoint);
                }
            }
            else
            {
                Owner.Sender.SendMessage(new Package()
                {
                    Data         = "Room is not exist",
                    MesseggeType = MesseggeType.Error
                }, gamer.RemoteEndPoint);
            }
        }