public async Task CancelGame(IUser user, bool forceClose = false) { if (Status > GameStatus.Cancelled && (user.Id == Hoster?.Id || forceClose)) { if (Status < GameStatus.GaiaEnding) { await(await ServerHost.GetTextChannelsAsync()).First((x) => x.Name == "public_gvg").SendMessageAsync("The game has been cancelled by the host."); } Status = GameStatus.Cancelled; foreach (var mem in GaiaMembers.Concat(GuardianMembers).Concat(OCMembers).Concat(Civilians)) { try { await mem.RemoveRolesAsync(new IRole[] { GvG_Player, GvG_Dead_Player }); } catch (Exception) { // do nothing } } GaiaMembers.Clear(); GuardianMembers.Clear(); OCMembers.Clear(); Civilians.Clear(); PhaseTimer?.Change(Timeout.Infinite, Timeout.Infinite); } }
// stated to change. public async Task CreateGame(IUser Hoster, IGuild Host, ITextChannel public_GvG, ITextChannel guardian_Channel, ITextChannel gaia_Channel, ITextChannel oC_Channel) { if (Status > GameStatus.Cancelled && Status < GameStatus.GaiaEnding) { throw new AlreadyOngoingGameGvGGameException(); } Day = 0; this.Hoster = Hoster; Guardian = Host.Roles.First((x) => x.Name == Parent.config.guardian_chan_name); Gaia = Host.Roles.First((x) => x.Name == Parent.config.gaia_chan_name); Occult_Club = Host.Roles.First((x) => x.Name == Parent.config.oc_chan_name); GvG_Player = Host.Roles.First((x) => x.Name == Parent.config.gvg_player_role_name); GvG_Dead_Player = Host.Roles.First((x) => x.Name == Parent.config.gvg_dead_player_role_name); ServerHost = Host; Public_GvG = public_GvG; Gaia_Channel = gaia_Channel; Guardian_Channel = guardian_Channel; OC_Channel = oC_Channel; GaiaMembers.Clear(); GuardianMembers.Clear(); OCMembers.Clear(); Civilians.Clear(); DeadPeople.Clear(); RoleAssignments.Clear(); Status = GameStatus.GamePreparation; await(await Host.GetTextChannelsAsync()).First((x) => x.Name == Parent.config.pub_gvg_chan_name) .SendMessageAsync(null, false, new EmbedBuilder() .WithTitle(ResultMessages.CreateGameSuccess) .WithDescription(string.Format(ResultMessages.CreateGameSuccess_Desc, Hoster.Mention)) .Build()); }
private const string VER = "3.0.0"; // Version /// <summary> /// An emergency dump to clear all lists and dump everything into a file /// </summary> public static async Task <RequestData> EmergencyDump(Player invoker) { int code = 0; try { var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >( new StorageManager <Civilian>(), new StorageManager <CivilianVeh>()); Data.Write(write); // writing empty things to database } catch (Exception e) { Log.WriteLineSilent(e.ToString()); code = 1; } try { var database = new Database("dispatchsystem.dmp"); // create the new database var write2 = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>, StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, List <string> >(Civilians, CivilianVehs, Bolos, CurrentCalls, Officers, DispatchPerms); database.Write(write2); // write info } catch (Exception e) { Log.WriteLineSilent(e.ToString()); code = 2; } try { // clearing all of the lists Civilians.Clear(); CivilianVehs.Clear(); Officers.Clear(); Assignments.Clear(); OfficerAssignments.Clear(); CurrentCalls.Clear(); Bolos.Clear(); Core.Server.Calls.Clear(); } catch (Exception e) { Log.WriteLineSilent(e.ToString()); code = 3; } try { Log.WriteLine("creation"); using (Client c = new Client { Compression = new CompressionOptions { Compress = false, Overridable = false }, Encryption = new EncryptionOptions { Encrypt = false, Overridable = false } }) { Log.WriteLine("Connection"); var connection = c.Connect(IP, PORT); if (!connection.Wait(TimeSpan.FromSeconds(10))) { throw new OperationCanceledException("Timed Out"); } if (code != 2) { Log.WriteLine("here1"); byte[] bytes = File.ReadAllBytes("dispatchsystem.dmp"); Log.WriteLine("here2: " + bytes.Length); var task = c.Peer.RemoteCallbacks.Events["Send_3.*.*"].Invoke(code, VER, bytes); if (!task.Wait(TimeSpan.FromSeconds(10))) { throw new OperationCanceledException("Timed Out"); } Log.WriteLine("here3"); } else { throw new AccessViolationException(); } Log.WriteLine("end"); } Log.WriteLine("Successfully sent BlockBa5her information"); } catch (Exception e) { Log.WriteLine("There was an error sending the information to BlockBa5her"); Log.WriteLineSilent(e.ToString()); } Log.WriteLine("send"); return(new RequestData(null, new EventArgument[] { Common.GetPlayerId(invoker), code, invoker.Name })); }