public static User CreateRandomNewUser() { User user; do { user = new User { Name = Consts.GUEST_PREFIX + _userNumber++ }; } while (!Users.TryAdd(user.Name, user)); LostBeats.TryAdd(user.Name, 0); return user; }
public override Response DoWork(string request) { var workRequest = JsonConvert.DeserializeObject<AddUserRequest>(request); var workResponse = new AddUserResponse(); var user = new User {Name = workRequest.UserName}; workResponse.Status = Statuses.Ok; if (!Server.Users.TryAdd(user.Name, user)) { workResponse.Status = Statuses.DuplicateUser; } return workResponse; }
public GameObject(User user) { Interlocked.Increment(ref GameIdSeq); Id = GameIdSeq; var rnd = new Random(); if (rnd.Next(100) < 50) { PlayerWhite = user; } else { PlayerBlack = user; } }
public ActionResult StartFree() { User newPlayer = null; if (Request.IsAuthenticated) { newPlayer = new User { Name = User.Identity.Name }; } var requestCreateGame = new CreateGameRequest { NewPlayer = newPlayer }; var responseCreateGame = ServerProvider.MakeRequest<CreateGameResponse>(requestCreateGame); int? gameId = null; if (responseCreateGame.Status == Statuses.Ok) { gameId = responseCreateGame.ID; FormsAuthentication.SetAuthCookie(responseCreateGame.FirstPlayer.Name, false); var requestJoinGame = new JoinGameRequest { GameID = gameId.Value, NewPlayer = responseCreateGame.FirstPlayer }; var responseJoinGame = ServerProvider.MakeRequest(requestJoinGame); if (responseJoinGame.Status != Statuses.Ok) { gameId = null; } } return Json(gameId, JsonRequestBehavior.AllowGet); }