public static async Task AddMapFromUrl(CServerConnection con, string mapUrl) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mapUrl); // If required by the server, set the credentials. request.Headers["UserAgent"] = "Mozilla/5.0"; // Get the response. WebResponse response = await request.GetResponseAsync(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream, CodePagesEncodingProvider.Instance.GetEncoding(1252)); // Read the content. string responseFromServer = reader.ReadToEnd(); //var responseFromServer = await DownloadFileAsync(mapUrl); /// Create the map await CFileIO.Default.WriteTextAsync("test.Map.Gbx", responseFromServer); var tick = Environment.TickCount; await con.Events.WriteFile("mx/" + tick + ".Map.Gbx", responseFromServer); await con.Events.InsertMap("mx/" + tick + ".Map.Gbx"); await con.RefreshMapCompletely("null", "mx/" + tick + ".Map.Gbx"); }
public static async Task AddServer(CServerConfig serverConfig) { var client = new CServerConnection(); XmlRPC_Clients[serverConfig.ServerLogin] = client; { var connected = await client.CreateConnection(IPAddress.Parse(serverConfig.IPAddress), serverConfig.Port); if (connected) { CDebug.Log("Connected!"); } else { CDebug.ErrorLog("Couldn't connect to : " + serverConfig.IPAddress + ":" + serverConfig.Port); } } for (int i = 0; i < servicesTypeFound.Count; i++) { var value = servicesTypeFound[i]; if (value.GetInterfaces().Contains(typeof(IServiceServer)) && value.GetInterfaces().Contains(typeof(IServiceStartAutomatically))) { var s = client.ServerServices[value] = Activator.CreateInstance(value) as CService; ((IServiceServer)s).Service_ServerConnection = client; await((IServiceServer)s).ServerAdded(); } } for (int i = 0; i < Plugins.Count; i++) { await Plugins[i].OnServerAdded(serverConfig.ServerLogin); } }
void OnGettingMapInformation(CServerConnection con, CMap map) { GS_LoadedMaps.SetNowForServers(con.MapList.Where(m => m.Value.LoadingState == HalfClass.CurrentState.AllInfoFilled).Count(), con); GS_MapCount.SetNowForServers(con.MapList.Count, con); CDebug.Log("Received informations for " + map.Name); }
public void OnGettingMapInformation_Invoke(CServerConnection con, CMap map) { OnGettingMapInformation?.Invoke(con, map); }
protected override void Service_Connections() { while ( m_ConnectionListener.Pending() ) { Socket socket = m_ConnectionListener.AcceptSocket(); ESessionID id = Allocate_Connection_ID(); CServerConnection connection = new CServerConnection( id ); connection.Initialize( socket ); Add_Connection( connection ); Add_Event( ENetworkEvent.Connection_Success, id ); } base.Service_Connections(); }