Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 |
/*============================================================================= WebServer is responsible for listening to requests on the selected http port and will guide requests to the correct application. =============================================================================*/ class WebServer extends IpDrv.TcpLink; var config string Applications[10]; var config string ApplicationPaths[10]; var config int ListenPort; var config int MaxConnections; var config string ServerName; var config bool bEnabled; var config int DefaultApplication; #if IG_TRIBES3_ADMIN // glenn: admin support var config int ExpirationSeconds; // How long images can be cached .. default is 24 hours #endif var string ServerURL; var WebApplication ApplicationObjects[10]; var int ConnectionCount; #if IG_TRIBES3_ADMIN // glenn: admin support // var int ConnId; #endif function BeginPlay() { local int i; local class<WebApplication> ApplicationClass; local IpAddr l; local string s; Log("WebServer.BeginPlay"); if(!bEnabled) { Log("Webserver is not enabled. Set bEnabled to True in Advanced Options."); Destroy(); return; } Super.BeginPlay(); for(i=0;i<10;i++) { if(Applications[i] == "") break; ApplicationClass = class<WebApplication>(DynamicLoadObject(Applications[i], class'Class')); if(ApplicationClass != None) { log("WebServer: initializing "$ApplicationClass); ApplicationObjects[i] = New(None) ApplicationClass; ApplicationObjects[i].Level = Level; ApplicationObjects[i].WebServer = Self; ApplicationObjects[i].Path = ApplicationPaths[i]; ApplicationObjects[i].Init(); } } if(ServerName == "") { GetLocalIP(l); s = IpAddrToString(l); i = InStr(s, ":"); if(i != -1) s = Left(s, i); ServerURL = "http://"$s; } else ServerURL = "http://"$ServerName; if(ListenPort != 80) ServerURL = ServerURL $ ":"$string(ListenPort); Log("WebServer: url="$ServerURL); BindPort( ListenPort ); Listen(); } event Destroyed() { local int i; Log("WebServer.Destroyed"); for(i=0;i<10;i++) if(ApplicationObjects[i] != None) { ApplicationObjects[i].Cleanup(); ApplicationObjects[i].Level = None; ApplicationObjects[i].WebServer = None; ApplicationObjects[i] = None; } Super.Destroyed(); } event GainedChild( Actor C ) { Log("WebServer.GainedChild: "$C.Name); Super.GainedChild(C); ConnectionCount++; // if too many connections, close down listen. if(MaxConnections > 0 && ConnectionCount > MaxConnections && LinkState == STATE_Listening) { Log("WebServer: Too many connections - closing down Listen."); Close(); } } event LostChild( Actor C ) { Log("WebServer.LostChild: "$C.Name); Super.LostChild(C); ConnectionCount--; // if closed due to too many connections, start listening again. if(ConnectionCount <= MaxConnections && LinkState != STATE_Listening) { Log("WebServer: Listening again - connections have been closed."); Listen(); } } function WebApplication GetApplication(string URI, out string SubURI) { local int i, l; Log("WebServer.GetApplication: "$URI $", "$SubURI); SubURI = ""; for(i=0;i<10;i++) { if(ApplicationPaths[i] != "") { l = Len(ApplicationPaths[i]); if(Left(URI, l) == ApplicationPaths[i] && (Len(URI) == l || Mid(URI, l, 1) == "/")) { SubURI = Mid(URI, l); return ApplicationObjects[i]; } } } return None; } #if IG_TRIBES3_ADMIN // glenn: admin support defaultproperties { ExpirationSeconds=86400 ListenPort=80 LinkMode=MODE_Text AcceptClass=class'WebConnection' MaxConnections=30 DefaultApplication=-1 } #else // commented out because defaultproperties parser does not support #if/#else/#endif //defaultproperties //{ // ListenPort=80 // LinkMode=MODE_Text // AcceptClass=class'WebConnection' // MaxConnections=30 // DefaultApplication=-1 //} #endif |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |