private void CreatRoom(IPackage package) { var conectionData = (IConectionData)package.Data; var client_passport = package.Sender_Passport; var newGameSettings = conectionData.GameSetings; var player_name = conectionData.PlayerName; // получить Gamer по id из списка ожидающих IGamer gamer = ManagerRoom.GetGamerByGuid(client_passport); gamer.SetId(player_name, client_passport); // создать комнату IRoom newGameRoom = ManagerRoom.AddRoom(newGameSettings, client_passport); newGameRoom.CreatorPassport = gamer.Passport; (newGameRoom as IGameRoom).OnNotifyMustRemoveRoom += OnNotifyMustRemoveRoom_EventHandler; newGameRoom.RUN(); // добавить в нее игрока //var room_endpoint = ManagerRoom.MooveGamerToRoom(gamer, newGameRoom.Passport); var room_endpoint = newGameRoom.Reciever.LockalEndPoint; Addresssee addres = new Addresssee(room_endpoint); var roominfo = new RoomInfo() { RoomPassport = newGameRoom.Passport, roomEndpoint = addres, mapSize = newGameSettings.MapSize }; Owner.Sender.SendMessage(new Package() { Data = roominfo, MesseggeType = MesseggeType.RoomInfo }, gamer.RemoteEndPoint); //newGameRoom.RUN(); //(newGameRoom as IGameRoom).NotifyGameRoomForEvent(new NotifyJoinedPlayerData() { JoinedAddresssee = gamer }); // инициировать начало игры (по крайней мере для теста - если создатель указывает колич.игроков =1 при создании) //if (newGameRoom.Gamers.Count() == newGameRoom.GameSetings.MaxPlayersCount) //{ // IPackage pack = new Package() // { // MesseggeType = MesseggeType.StartGame, // Data = null, // }; // Owner.Sender.SendMessage(pack, newGameRoom.Gamers); //Управляющая комната отсылает участникам игровой комнаты // //уведомляем игровую комнату о начале: // (newGameRoom as IGameRoom).NotifyGameRoomForEvent(new NotifyStartGameData() { EnforceStartGame = true }); //} }
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); } }