private void RemoveUser(Game game) { var time = DateTimeOffset.UtcNow - GameHost._UserLiveTime; var userList = game.GameUser.Where(p => !string.IsNullOrEmpty(p.Login) && p.Login != "Вестерос" && p.LastUpdate < time); //if (DateTimeOffset.UtcNow - game.CreateTime < _UserLiveTime) // userList = userList.Where(p => string.IsNullOrEmpty(p.HomeType)); //лишаем лордства неактивных foreach (var user in userList.ToList()) { var profile = GamePortalServer.GetProfileByLogin(user.Login); if (game.OpenTime != null) { GamePortalServer.StopUserGame(user.Login, game.Id); } else if (!string.IsNullOrEmpty(user.HomeType)) { GameHost.AddUserNotifiFunc(profile, string.Format("dynamic_leftGame1*{0}", user.HomeType)); } if (!string.IsNullOrEmpty(user.HomeType)) { var whois = profile == null ? user.Login : profile.Api["FIO"]; var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat", JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_Exile*homeType_{user.HomeType}*{whois}" })); //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_Exile*homeType_{0}*{1}", // user.HomeType, // profile == null ? user.Login : profile.Api["FIO"])); } //наблюдателей удаляем if (string.IsNullOrEmpty(user.HomeType)) { game.DbContext.GameUser.Remove(user); } else { _DeniedLogin.Add(user.Login); user.Login = null; //сообщаем что требуется замена if (game.OpenTime != null) { GameHost.AddGameNotifiFunc(game.ToWCFGame()); } } } //если партию покинули все игроки if (game.HomeUsersSL.All(p => p.Login == null)) { game.CloseTime = DateTimeOffset.UtcNow; } }
public void DisConnectTask(WCFGameUser clientUser) { GameHost.TaskFactory.StartNew(() => { try { using (Agot2p6Entities dbContext = new Agot2p6Entities()) { GameUser user = dbContext.GameUser.SingleOrDefault(p => p.Id == clientUser.Id); if (user == null || !clientUser.Check(user)) { return; } Game game = user.Game1; if (game.CreateTime < DateTimeOffset.UtcNow && game.CloseTime == null && !string.IsNullOrEmpty(user.HomeType)) { var profile = GamePortalServer.GetProfileByLogin(user.Login); if (game.OpenTime != null) { GamePortalServer.StopUserGame(user.Login, game.Id); } else { GameHost.AddUserNotifiFunc(profile, string.Format("dynamic_leftGame1*{0}", user.HomeType)); } if (!string.IsNullOrEmpty(user.HomeType)) { var whois = profile == null ? user.Login : profile.Api["FIO"]; var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat", JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_Exile*{user.HomeType}*{whois}" })); //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_Exile*homeType_{0}*{1}", // user.HomeType, // profile == null ? user.Login : profile.Api["FIO"])); } _DeniedLogin.Add(user.Login); user.Login = null; dbContext.SaveChanges(); //TODO перенести в Realease if (game.OpenTime != null) { GameHost.AddGameNotifiFunc(game.ToWCFGame()); } } } } catch (Exception exp) { GameException.NewGameException(clientUser.Game, "Не удалось отключиться от игры.", exp, false); } }); }
private void RemoveUser(Game game) { DateTimeOffset time = dateTimeNow - _UserLiveTime; IEnumerable <GameUser> userList = game.GameUser.Where(p => !string.IsNullOrEmpty(p.Login) && p.Login != "Вестерос" && p.LastUpdate < time); //лишаем лордства неактивных foreach (GameUser user in userList.ToList()) { //лорды if (!string.IsNullOrEmpty(user.HomeType)) { WCFUser profile = GamePortalServer.GetProfileByLogin(user.Login); // bool hasVaule = _DeniedLogin.TryGetValue(user.Login, out int oldLiaveCount); // int newLiaveCount = game.OpenTime == null ? GameHost.MaxLiaveCount + 1 : oldLiaveCount + 1; //#if !DEBUG // if (!hasVaule) _DeniedLogin.TryAdd(user.Login, newLiaveCount); // else _DeniedLogin.TryUpdate(user.Login, newLiaveCount, oldLiaveCount); //#endif if (game.OpenTime != null) { GamePortalServer.StopUserGame(user.Login, game.Id, 0, royalPardon); } else { GameHost.AddUserNotifiFunc(profile, $"dynamic_leftGame1*unknown home");//{user.HomeType} } string whois = profile == null ? user.Login : profile.Api["FIO"]; int liaveCount = profile.UserGames.Count(p => p.GameId == this.GameId && p.EndTime.HasValue && !p.IsIgnoreHonor); if (liaveCount > GameHost.MaxLiaveCount) { ChatService.AddChat(new Chat() { Creator = "Вестерос", Message = $"dynamic_Exile*homeType_{user.HomeType}*Faceless Men" }); //{whois} } else if (game.OpenTime != null) { ChatService.AddChat(new Chat() { Creator = "Вестерос", Message = $"dynamic_leftGame*homeType_{user.HomeType}*Faceless Men*{GameHost.MaxLiaveCount - liaveCount + 1}" }); //{whois} } user.Login = null; //сообщаем что требуется замена if (game.OpenTime != null) { GameHost.AddGameNotifiFunc(game.ToWCFGame()); } } //наблюдателей удаляем else { game.DbContext.GameUser.Remove(user); } } royalPardon = false; //если партию покинули все игроки if (game.HomeUsersSL.All(p => p.Login == null)) { game.CloseTime = dateTimeNow; } }
public void DisConnectTask(WCFGameUser clientUser) { using (Agot2p6Entities dbContext = new Agot2p6Entities()) { GameUser user = dbContext.GameUser.SingleOrDefault(p => p.Id == clientUser.Id); if (user == null || !clientUser.Check(user)) { return; } Game game = user.Game1; game.GameHost = this; game.DbContext = dbContext; if (game.CreateTime < DateTimeOffset.UtcNow && game.CloseTime == null && !string.IsNullOrEmpty(user.HomeType)) { // bool hasVaule = _DeniedLogin.TryGetValue(user.Login, out int oldLiaveCount); // int newLiaveCount = game.OpenTime == null ? GameHost.MaxLiaveCount + 1 : oldLiaveCount + 1; //#if !DEBUG // if (!hasVaule) _DeniedLogin.TryAdd(user.Login, newLiaveCount); // else _DeniedLogin.TryUpdate(user.Login, newLiaveCount, oldLiaveCount); //#endif GamePortal.WCFUser profile = GamePortalServer.GetProfileByLogin(user.Login); if (game.OpenTime != null) { GamePortalServer.StopUserGame(user.Login, game.Id); #if DEBUG Capitulate(game, user); #endif } else { GameHost.AddUserNotifiFunc(profile, $"dynamic_leftGame1*unknown home");//{user.HomeType} } string whois = profile == null ? user.Login : profile.Api["FIO"]; int liaveCount = profile.UserGames.Count(p => p.GameId == this.GameId && p.EndTime.HasValue && !p.IsIgnoreHonor); if (liaveCount > GameHost.MaxLiaveCount) { ChatService.AddChat(new Chat() { Creator = "Вестерос", Message = $"dynamic_Exile*homeType_{user.HomeType}*Faceless Men" }); //{whois} } else if (game.OpenTime != null) { ChatService.AddChat(new Chat() { Creator = "Вестерос", Message = $"dynamic_leftGame*homeType_{user.HomeType}*Faceless Men*{GameHost.MaxLiaveCount - liaveCount + 1}" }); //{whois} } user.Login = null; dbContext.SaveChanges(); if (game.OpenTime != null) { GameHost.AddGameNotifiFunc(game.ToWCFGame()); } } } }