public override void Login() { var baseInfo = new JsonData(); baseInfo["nickname"] = "风从海上来"; baseInfo["figure"] = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2043575092,1720307024&fm=26&gp=0.jpg"; Servlet.SetBaseInfo(baseInfo.ToJson()); }
private IEnumerator Start() { #if UNITY_EDITOR _assetLoader = gameObject.AddComponent <LocalAsset>(); _client = gameObject.AddComponent <EditorClient>(); #elif UNITY_ANDROID var bundles = gameObject.AddComponent <Bundles>(); bundles.StartDownloads(BundlesUri); _assetLoader = bundles; _client = gameObject.AddComponent <AndroidClient>(); #endif while (!_assetLoader.IsDone()) { yield return(null); } _scenes = gameObject.AddComponent <Scenes>(); _luaState = gameObject.AddComponent <LuaState>(); _servlet = gameObject.AddComponent <Servlet>(); Client.Login(); }
public Servlet this[string context] { get { context = "/" + context.Trim('/'); if (!servlets.ContainsKey(context)) { return(null); } return(servlets[context]); } set { context = "/" + context.Trim('/'); Servlet oldValue = servlets.ContainsKey(context) ? servlets[context] : null; value.Log = new ServerLogger(this); value.ContextPath = context; value.IPEndPoint = this.endpoint; value.Initialize(); servlets[context] = value; if (oldValue != null) { oldValue.Destroy(); } } }
public void RegisterServlet(string relativUrl, Servlet servlet) { servlets[relativUrl] = servlet; }
public static void Main(string[] args) { string root = "."; string configFileName = "sharpclaws.xml"; if (args.Length > 0) { root = args[0]; } if (args.Length > 1) { configFileName = args[1]; } string filename = Path.Combine(root, configFileName); if (args.Length > 2 || !File.Exists(filename)) { Console.Error.WriteLine("Configuration file {0} not found", filename); Console.Error.WriteLine("Usage: {0} [root] [config-file]", Environment.CommandLine); Console.Error.WriteLine(" root: the directory to run in. default: ."); Console.Error.WriteLine(" config-file: the xml configuration file. default: sharpclaws.xml"); Environment.Exit(1); } XmlDocument config = new XmlDocument(); try { config.Load(filename); } catch (XmlException e) { Console.Error.WriteLine("Configuration file {0} has an invalid format:", filename); Console.Error.WriteLine(e); Environment.Exit(1); } XPathNavigator nav = config.CreateNavigator().SelectSingleNode("/server"); if (nav == null) { Console.Error.WriteLine("Configuration file {0} has an invalid format: root <server> tag not found", filename); Environment.Exit(1); } LogLevel logLevel = LogLevel.Info; string logLevelAttribute = nav.GetAttribute("log-level", string.Empty); if (logLevelAttribute != string.Empty) { try { logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), logLevelAttribute, true); } catch (ArgumentException) { Console.Error.WriteLine("Invalid log-level {0}", logLevelAttribute); } } TextWriter logFileWriter = Console.Out; string logFileAttribute = nav.GetAttribute("log", string.Empty); if (logFileAttribute != string.Empty) { string logFileName = Path.Combine(root, logFileAttribute); StreamWriter writer = new StreamWriter(new FileStream(logFileName, FileMode.Append)); writer.AutoFlush = true; logFileWriter = writer; } logger = new TextWriterLogger(logLevel, logFileWriter); int port = 80; IPAddress ip = IPAddress.Any; string portAttribute = nav.GetAttribute("port", string.Empty); string ipAttribute = nav.GetAttribute("interface", string.Empty); if (portAttribute != string.Empty) { port = Convert.ToInt32(portAttribute); } if (ipAttribute != string.Empty) { ip = GetAddress(ipAttribute); if (ip == null) { logger.Error("interface={0} but no local address has this prefix", ipAttribute); Environment.Exit(1); } } server = new Server(ip, port); server.Log = logger; Console.CancelKeyPress += new ConsoleCancelEventHandler(SignalExit); XPathNodeIterator iterator = nav.SelectChildren("servlet", string.Empty); while (iterator.MoveNext()) { string context = iterator.Current.GetAttribute("context", string.Empty); // returns empty on missing --> "/" if (!context.StartsWith("/")) { context = "/" + context; } if (!context.EndsWith("/")) { context = context + "/"; } string className = iterator.Current.GetAttribute("class", string.Empty); string assemblyName = iterator.Current.GetAttribute("assembly", string.Empty); Dictionary <string, string> servletConfig = new Dictionary <string, string>(); XPathNodeIterator paramsIterator = iterator.Current.SelectChildren("param", string.Empty); while (paramsIterator.MoveNext()) { string name = paramsIterator.Current.GetAttribute("name", string.Empty); if (name == null) { logger.Error("<param> must have a name given."); Environment.Exit(1); } servletConfig.Add(name, paramsIterator.Current.Value); } if (className == string.Empty) { logger.Error("Servlet mapped to {0} has no class specified", context); Environment.Exit(1); } if (assemblyName == string.Empty) { logger.Error("Servlet mapped to {0} has no assembly specified", context); Environment.Exit(1); } try { Assembly assembly = Assembly.LoadFile(Path.GetFullPath(Path.Combine(root, assemblyName))); Type type = assembly.GetType(className, true, true); if (!type.IsSubclassOf(typeof(Servlet))) { throw new Exception(string.Format("Type {0} is not a subclass of {1}", type, typeof(Servlet))); } ConstructorInfo constructor = type.GetConstructor(new Type[0]); Servlet servlet = (Servlet)constructor.Invoke(null); servlet.Configuration = servletConfig; server[context] = servlet; } catch (Exception e) { logger.Error("Couldn't instantiate class {0} from assembly {1}", className, assemblyName); logger.Error(e); Environment.Exit(1); } } try { server.Run(); } catch (Exception e) { logger.Error("Server exception"); logger.Error(e); Environment.Exit(2); } }
private static void updateConnections() { lock (_network) { //Start and/or update network IP list List <IPAddress> newIpAdresses = new List <IPAddress>(); //for storing IP adresses that the programm did not yet start listening on List <IPAddress> presentIpAdresses = new List <IPAddress>(); //for storing all IP addresses of the right type foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces()) { if (netInterface.Description.Contains("Microsoft Hosted Network Virtual Adapter")) //find the HostedNet adapter { if (netInterface.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Down) // if it's down' { HostedNetUp = false; StartHostedNetwork(); ///start it } else { HostedNetUp = true; } } if (netInterface.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up) //check if the interface is up { IPInterfaceProperties ipProps = netInterface.GetIPProperties(); foreach (UnicastIPAddressInformation addr in ipProps.UnicastAddresses) { if (addr.Address.AddressFamily == AddressFamily.InterNetwork) //checks if the adress is an IPv4 one { presentIpAdresses.Add(addr.Address); if (_network.Length > 0) { if (Array.Exists(_network, p => p.LocalIp.Equals(addr.Address))) { //IP address is already on the list } else { newIpAdresses.Add(addr.Address); //add it to the list, it's not there } } else { newIpAdresses.Add(addr.Address); //networking is not initialised, put everything on the list } } } } } List <Servlet> newlist = new List <Servlet>(); int removedAddresses = 0; String listofIpAdresses = ""; //string that stores every IP address that hte programm is working with foreach (var connection in _network) { if (presentIpAdresses.Exists(p => p.Equals(connection.LocalIp))) //check if the connection still exists { newlist.Add(connection); //this is a bad way to retry connections, but I have no better ideas at het moment! if (!connection.IsActive()) //try resetting the connection a bit! { Logging.Add("Resetting connection " + connection.LocalIp); connection.Reset(); } listofIpAdresses += connection.LocalIp.ToString() + ", "; } else { removedAddresses++; connection.Dispose(); //if it is not, dispose of it } } if (newIpAdresses.Count > 0 || removedAddresses > 0) { foreach (var connection in newIpAdresses) { var newconnection = new Servlet(connection); newconnection.Readnetwork(); newlist.Add(newconnection); listofIpAdresses += connection.ToString() + ", "; } Logging.Add("IP addresses changed: the connections are " + listofIpAdresses); _network = newlist.ToArray <Servlet>(); } } }