private void button1_Click(object sender, EventArgs e) { var channelFactory = new DuplexChannelFactory<IPoLServer>(new InstanceContext(this), "pol"); var clientChannel = channelFactory.CreateChannel(); var enterLobbyReq = new DataContracts.EnterLobbyRequest(); enterLobbyReq.Player = new DataContracts.Player(); enterLobbyReq.Player.Name = "Pippo"; var enterLobbyResp = clientChannel.EnterLobby(enterLobbyReq); var createroomReq = new DataContracts.CreateRoomRequest(); createroomReq.GameRoom = new DataContracts.GameRoom(); createroomReq.GameRoom.Name = "Room1"; createroomReq.GameRoom.Description = "desc Room1"; var createroomResp = clientChannel.CreateRoom(createroomReq); createroomReq = new DataContracts.CreateRoomRequest(); createroomReq.GameRoom = new DataContracts.GameRoom(); createroomReq.GameRoom.Name = "Room2"; createroomReq.GameRoom.Description = "desc Room2"; createroomResp = clientChannel.CreateRoom(createroomReq); var getallroomsReq = new DataContracts.GetAllRoomsRequest(); var getallroomsResp = clientChannel.GetAllRooms(getallroomsReq); }
public EnterLobbyResponse EnterLobby(EnterLobbyRequest request) { EnterLobbyResponse response = new EnterLobbyResponse(); rwLock.EnterWriteLock(); try { response.Success = !gameLobby.Players.ContainsKey(request.Player.Name); if(response.Success) { IPoLServerCallback channel = OperationContext.Current.GetCallbackChannel<IPoLServerCallback>(); ((IContextChannel)channel).Closed += new EventHandler(channel_Closed); gameLobby.Players.Add(request.Player.Name, new dm.Player(request.Player.Name, channel)); } } finally { rwLock.ExitWriteLock(); } return response; }