public async Task RefreshServerInfo() { var call = await Manager.AsyncSendCall(GbxParam.Create("GetMainServerPlayerInfo")); var hash = (Dictionary <string, object>)call.Parameters[0]; ServerInfo = new CServerInfo(); ServerInfo.Login = (string)hash["Login"]; if (CManiaNextControl.XmlRPC_Clients.ContainsValue(this)) { var keys = new List <string>(); foreach (var kvp in CManiaNextControl.XmlRPC_Clients) { if (ServerInfo.Login == kvp.Key && this != kvp.Value) { CManiaNextControl.XmlRPC_Clients[kvp.Key] = this; } else if (kvp.Key != ServerInfo.Login && this == kvp.Value) { keys.Add(kvp.Key); } } for (int i = 0; i < keys.Count; i++) { CManiaNextControl.XmlRPC_Clients.Remove(keys[i]); } CManiaNextControl.XmlRPC_Clients[ServerInfo.Login] = this; } }
public static async Task InitServer(string serverLogin) { var client = XmlRPC_Clients[serverLogin]; await client.Manager.AsyncSendCall(GbxParam.Create("Authenticate", ServersConfig[serverLogin].SuperAdminLogin, ServersConfig[serverLogin].SuperAdminPassword)); await client.Manager.AsyncSendCall(GbxParam.Create("EnableCallbacks", true)); await client.Manager.AsyncSendCall(GbxParam.Create("SetApiVersion", "2013-04-16")); await client.Manager.AsyncSendCall(GbxParam.Create("ChatSendServerMessage", "The controller successfuly made a link to this server!")); await client.Refresh(); client.IsLoaded = true; foreach (var service in client.ServerServices) { await((IServiceServer)service.Value).ServerLoaded(); } for (int i = 0; i < Plugins.Count; i++) { await Plugins[i].OnServerLoaded(client.ServerInfo.Login); } await client.ApplyFullInformationsToMaps(); }
public async Task RefreshMapList() { var fileNames = new List <string>(); (await Manager.AsyncSendCall(GbxParam.Create("GetMapList", 2000, 0))) .Parameters[0] .TypeCast <List <object> >() .ForEach((object value) => { var hashtable = value.TypeCast <Dictionary <string, object> >(); string fileName = (string)hashtable["FileName"]; string UId = (string)hashtable["UId"]; if (!MapList.ContainsKey(UId)) { MapList[UId] = new CMap(); } var map = MapList[UId]; map.UId = UId; map.FileName = fileName; map.Name = (string)hashtable["Name"]; map.Author = (string)hashtable["Author"]; map.Environnement = (string)hashtable["Environnement"]; map.LoadingState = HalfClass.CurrentState.PrimaryInfoFilled; fileNames.Add(fileName); } ); }
public async Task InsertMap(string filePath) { var gbx = await con.Manager.AsyncSendCall(GbxParam.Create("InsertMap", filePath)); if (gbx.isError) { await ChatSendServerMessage("$f00ERROR: " + gbx.ErrorString); } }
public async Task WriteFile(string filePath, string fileContent) { GbxParam sentGBX = GbxParam.Create("WriteFile", filePath, CodePagesEncodingProvider.Instance.GetEncoding(1252).GetBytes(fileContent)); var gbx = await con.Manager.AsyncSendCall(sentGBX); if (gbx.isError) { await ChatSendServerMessage("$f00ERROR: " + gbx.ErrorString + " \nSent XML:\n"); } }
public async Task RefreshPlayerList() { var call = await Manager.AsyncSendCall(GbxParam.Create("GetPlayerList", 510, 0)); foreach (Dictionary <string, object> dico in (List <object>)call.Parameters[0]) { if (!CPlayer.AllPlayers.TryGetValue((string)dico["Login"], out var player)) { player = new CPlayer() { User = new CUser() { Login = (string)dico["Login"] }, NickName = (string)dico["NickName"], PlayerId = (int)dico["PlayerId"], TeamId = (int)dico["TeamId"], IsSpectator = (int)dico["TeamId"] > 0, LadderRanking = (int)dico["LadderRanking"], Server = this, }; } else { player.NickName = (string)dico["NickName"]; player.PlayerId = (int)dico["PlayerId"]; player.TeamId = (int)dico["TeamId"]; player.IsSpectator = (int)dico["TeamId"] > 0; player.LadderRanking = (int)dico["LadderRanking"]; player.Server = this; } player.LoadingState = HalfClass.CurrentState.PrimaryInfoFilled; CPlayer.AllPlayers[player.User.Login] = player; // Get detailed info call = await Manager.AsyncSendCall(GbxParam.Create("GetDetailedPlayerInfo", player.User.Login)); var dicoDetail = (Dictionary <string, object>)call.Parameters[0]; player.User.IPAddress = (string)dicoDetail["IPAddress"]; player.User.DownloadRate = (int)dicoDetail["DownloadRate"]; player.User.UploadRate = (int)dicoDetail["UploadRate"]; player.User.Language = (string)dicoDetail["Language"]; player.User.Player = player; player.LoadingState = HalfClass.CurrentState.AllInfoFilled; } }
public async Task ApplyFullInformationsToMaps() { foreach (var map in MapList.Values) { var hashtable = (await Manager.AsyncSendCall(GbxParam.Create("GetMapInfo", map.FileName))) .Parameters[0] .TypeCast <Dictionary <string, object> >(); map.Convert(hashtable); map.LoadingState = HalfClass.CurrentState.AllInfoFilled; CManiaNextControl.Events.OnGettingMapInformation_Invoke(this, map); } }
public async Task RefreshMapCompletely(string uid, string filemapname) { MapList.TryGetValue(uid, out var map); if (map == null) { map = new CMap() { UId = uid, FileName = filemapname } } ; var hashtable = (await Manager.AsyncSendCall(GbxParam.Create("GetMapInfo", map.FileName))) .Parameters[0] .TypeCast <Dictionary <string, object> >(); map.Convert(hashtable); map.LoadingState = HalfClass.CurrentState.AllInfoFilled; CManiaNextControl.Events.OnGettingMapInformation_Invoke(this, map); }
/// <summary> /// /// </summary> /// <param name="server">Parameter ignored if players is not empty. If null, this will be sent to all servers</param> /// <param name="timeBeforeHide"></param> /// <param name="players"></param> public async void Send(XmlRPCManager[] servers = null, int timeBeforeHide = 0, params CPlayer[] players) { if (!hasCorrectId) { throw new IncorrectIDException("No ID was put."); } if (!hasCorrectName) { throw new IncorrectNameException("No name was put."); } if (players == null || players.Count() == 0) { var sendToServers = servers; if (sendToServers == null || sendToServers.Length == 0) { sendToServers = CManiaNextControl.XmlRPC_Clients.Select(s => s.Value.Manager).ToArray(); } foreach (var server in sendToServers) { await server.AsyncSendCall(GbxParam.Create("SendDisplayManialinkPage", contents ?? "", timeBeforeHide, false), (gbx) => { Console.WriteLine($"result: hasError:{gbx.isError} errorCode:{gbx.ErrorCode} errorString:{gbx.ErrorString}"); }); } } else { foreach (var player in players) { await player.Server.Manager.AsyncSendCall(GbxParam.Create("SendDisplayManialinkPageToLogin", player.User.Login, contents ?? "", timeBeforeHide, false), (gbx) => { Console.WriteLine($"result: hasError:{gbx.isError} errorCode:{gbx.ErrorCode} errorString:{gbx.ErrorString}"); }); } } }
public async void ProcessCallback(CallbackContext cc) { var gbx = cc.gbx; var op = gbx.Parameters; switch (gbx.EventName) { case Code_PlayerConnect: { var player = await CPlayer.GetPlayerFromLogin((string)op[0], new[] { this }, false); player.LoadingState = HalfClass.CurrentState.PrimaryInfoFilled; CPlayer.AllPlayers[player.User.Login] = player; // Get detailed info var call = await Manager.AsyncSendCall(GbxParam.Create("GetDetailedPlayerInfo", player.User.Login)); var dicoDetail = (Dictionary <string, object>)call.Parameters[0]; player.User = new CUser(); player.User.IPAddress = (string)dicoDetail["IPAddress"]; player.User.DownloadRate = (int)dicoDetail["DownloadRate"]; player.User.UploadRate = (int)dicoDetail["UploadRate"]; player.User.Language = (string)dicoDetail["Language"]; player.User.Player = player; player.LoadingState = HalfClass.CurrentState.AllInfoFilled; await ApplyInterfaceHelpers(player); player.LoadingState = HalfClass.CurrentState.AllInfoFilled; player.ControllerLoaded = true; await Manager.AsyncSendCall(GbxParam.Create("ChatSendServerMessage", $"$0f0$555⏵ $fffWelcome $<{player.NickName}$z$s$> $fffto the server!")); TriggerListeners <PlayerConnect>(this, o => o.Callback(this, (string)op[0], (bool)op[1])); break; } case Code_PlayerDisconnect: { CPlayer.AllPlayers.TryGetValue((string)op[0], out var player); await Manager.AsyncSendCall(GbxParam.Create("ChatSendServerMessage", $"$0f0$555⏵ $fffBye bye $<{(player == null || player.NickName == null ? (string)op[0] : player.NickName)}$z$s$> $fff:(")); TriggerListeners <PlayerDisconnect>(this, o => o.Callback(this, (string)op[0], (string)op[1])); break; } case Code_PlayerChat: if (op.Length == 4) { TriggerListeners <PlayerChat>(this, o => o.Callback(this, (int)op[0], (string)op[1], (string)op[2], (bool)op[3])); } break; case Code_BeginMap: var smap = SMapInfo.Convert((Dictionary <string, object>)op[0]); await RefreshMapCompletely(smap.UId, smap.FileName); if (op.Length == 1) { TriggerListeners <BeginMap>(this, o => o.Callback(this, smap)); } break; case Code_EndMap: if (op.Length == 1) { TriggerListeners <EndMap>(this, o => o.Callback(this, SMapInfo.Convert((Dictionary <string, object>)op[0]))); } break; case Code_MapListModified: TriggerListeners <MapListModified>(this, o => o.Callback(this, 0, 0, true)); break; case Code_PlayerManialinkPageAnswer: TriggerListeners <PlayerManialinkPageAnswer>(this, o => o.Callback(this, (int)op[0], (string)op[1], (string)op[2])); break; } }
public async Task Maniaplanet_UI_SetAltScoresTableVisibility(bool state) { await con.Manager.AsyncSendCall(GbxParam.Create("Maniaplanet.UI.SetAltScoresTableVisibility", state)); }
public async Task <GbxParam> ChooseNextMap(string mapFileName) { return(await con.Manager.AsyncSendCall(GbxParam.Create("ChooseNextMap", mapFileName))); }
public async Task ChatSendServerMessage(string message) { await con.Manager.AsyncSendCall(GbxParam.Create("ChatSendServerMessage", message)); }