public Room CreateRoom(LoginToken token, string password = null) { if (VerifyClient(token)) { if (loggedInGuidToRoom.ContainsKey(token.token)) { return null; } while (rooms.ContainsKey(newRoomId)) { newRoomId++; } Room room = new Room(); for (int i = 0; i < 8; i++) { room.Seats.Add(new Seat() { State = SeatState.Empty }); } room.Seats[0].Account = loggedInGuidToAccount[token.token]; room.Seats[0].State = SeatState.Host; room.Id = newRoomId; room.OwnerId = 0; rooms.Add(newRoomId, room); if (loggedInGuidToRoom.ContainsKey(token.token)) { loggedInGuidToRoom.Remove(token.token); } loggedInGuidToRoom.Add(token.token, room); Console.WriteLine("created room {0}", newRoomId); return room; } Console.WriteLine("Invalid createroom call"); return null; }
public RoomOperationResult EnterRoom(LoginToken token, int roomId, bool spectate, string password, out Room room) { room = null; if (VerifyClient(token)) { Console.WriteLine("{1} Enter room {0}", roomId, token.token); if (loggedInGuidToRoom.ContainsKey(token.token)) { return RoomOperationResult.Locked; } if (rooms.ContainsKey(roomId)) { if (rooms[roomId].State == RoomState.Gaming) return RoomOperationResult.Locked; int seatNo = 0; foreach (var seat in rooms[roomId].Seats) { Console.WriteLine("Testing seat {0}", seatNo); if (seat.Account == null && seat.State == SeatState.Empty) { loggedInGuidToRoom.Add(token.token, rooms[roomId]); seat.Account = loggedInGuidToAccount[token.token]; seat.State = SeatState.GuestTaken; NotifyRoomLayoutChanged(roomId); Console.WriteLine("Seat {0}", seatNo); room = rooms[roomId]; return RoomOperationResult.Success; } seatNo++; } Console.WriteLine("Full"); return RoomOperationResult.Full; } } Console.WriteLine("Rogue enter room calls"); return RoomOperationResult.Auth; }
public RoomOperationResult EnterRoom(int roomId, bool spectate, string password, out Room room) { room = null; if (currentAccount == null) return RoomOperationResult.NotAutheticated; Trace.TraceInformation("{1} Enter room {0}", roomId, currentAccount.Account.UserName); if (currentAccount.CurrentRoom != null) { return RoomOperationResult.Locked; } ServerRoom serverRoom = null; Room clientRoom = null; lock (rooms) { if (!rooms.ContainsKey(roomId)) { return RoomOperationResult.Invalid; } else { serverRoom = rooms[roomId]; clientRoom = serverRoom.Room; } } lock (clientRoom) { if (clientRoom.IsEmpty || clientRoom.State == RoomState.Gaming) return RoomOperationResult.Locked; int seatNo = 0; foreach (var seat in clientRoom.Seats) { Trace.TraceInformation("Testing seat {0}", seatNo); if (seat.Account == null && seat.State == SeatState.Empty) { currentAccount.CurrentRoom = serverRoom; seat.Account = currentAccount.Account; seat.State = SeatState.GuestTaken; _NotifyRoomLayoutChanged(roomId); Trace.TraceInformation("Seat {0}", seatNo); _Unspectate(currentAccount); room = clientRoom; return RoomOperationResult.Success; } seatNo++; } Trace.TraceInformation("Full"); } return RoomOperationResult.Full; }
public void NotifyRoomUpdate(int id, Room room) { Application.Current.Dispatcher.BeginInvoke((ThreadStart)delegate() { var result = Rooms.FirstOrDefault(r => r.Id == id); if (result != null) { result.Room = room; } else { Rooms.Add(new RoomViewModel() { Room = room }); } if (CurrentRoom.Id == id) { CurrentRoom = new RoomViewModel() { Room = room }; } }); }
public Room CreateRoom(RoomSettings settings, string password = null) { if (currentAccount == null) return null; if (currentAccount.CurrentRoom != null) { return null; } lock (rooms) { while (rooms.ContainsKey(newRoomId)) { newRoomId++; } Room room = new Room(); int maxSeats = settings.GameType == GameType.Pk1v1 ? 2 : 8; for (int i = 0; i < maxSeats; i++) { room.Seats.Add(new Seat() { State = SeatState.Empty }); } room.Seats[0].Account = currentAccount.Account; room.Seats[0].State = SeatState.Host; room.Id = newRoomId; room.OwnerId = 0; room.Settings = settings; var srvRoom = new ServerRoom() { Room = room }; rooms.Add(newRoomId, srvRoom); currentAccount.CurrentRoom = srvRoom; Trace.TraceInformation("created room {0}", newRoomId); return room; } }