mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-28 16:05:54 -04:00
Increase 'Connection timeout' threshold to 30 seconds, avoid StringReader and replace with our own ReadLine() method.
This commit is contained in:
parent
25b8f453ad
commit
a28d2a38fd
@ -96,9 +96,8 @@ namespace ClassicalSharp.Network {
|
|||||||
prevCursorVisible = game.CursorVisible;
|
prevCursorVisible = game.CursorVisible;
|
||||||
|
|
||||||
game.Gui.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ), false );
|
game.Gui.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ), false );
|
||||||
if( ServerMotd.Contains( "cfg=" ) ) {
|
if( ServerMotd.Contains( "cfg=" ) && !game.PureClassic )
|
||||||
ReadWomConfigurationAsync();
|
ReadWomConfigAsync();
|
||||||
}
|
|
||||||
receivedFirstPosition = false;
|
receivedFirstPosition = false;
|
||||||
gzipHeader = new GZipHeaderReader();
|
gzipHeader = new GZipHeaderReader();
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@
|
|||||||
// This class was partially based on information from http://files.worldofminecraft.com/texturing/
|
// This class was partially based on information from http://files.worldofminecraft.com/texturing/
|
||||||
// NOTE: http://files.worldofminecraft.com/ has been down for quite a while, so support was removed on Oct 10, 2015
|
// NOTE: http://files.worldofminecraft.com/ has been down for quite a while, so support was removed on Oct 10, 2015
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
|
||||||
using ClassicalSharp.Map;
|
using ClassicalSharp.Map;
|
||||||
using ClassicalSharp.Network;
|
|
||||||
|
|
||||||
namespace ClassicalSharp.Network {
|
namespace ClassicalSharp.Network {
|
||||||
|
|
||||||
@ -24,39 +21,39 @@ namespace ClassicalSharp.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParseWomConfig( string page ) {
|
void ParseWomConfig( string page ) {
|
||||||
using( StringReader reader = new StringReader( page ) ) {
|
string line;
|
||||||
string line;
|
int start = 0;
|
||||||
while( ( line = reader.ReadLine() ) != null ) {
|
while( (line = ReadLine( ref start, page )) != null ) {
|
||||||
Utils.LogDebug( line );
|
Utils.LogDebug( line );
|
||||||
string[] parts = line.Split( new [] { '=' }, 2 );
|
int sepIndex = line.IndexOf('=');
|
||||||
if( parts.Length < 2 ) continue;
|
if( sepIndex == -1 ) continue;
|
||||||
string key = parts[0].TrimEnd();
|
string key = line.Substring(0, sepIndex).TrimEnd();
|
||||||
string value = parts[1].TrimStart();
|
string value = line.Substring(sepIndex + 1).TrimStart();
|
||||||
|
|
||||||
if( key == "environment.cloud" ) {
|
if( key == "environment.cloud" ) {
|
||||||
FastColour col = ParseWomColour( value, WorldEnv.DefaultCloudsColour );
|
FastColour col = ParseWomColour( value, WorldEnv.DefaultCloudsColour );
|
||||||
game.World.Env.SetCloudsColour( col );
|
game.World.Env.SetCloudsColour( col );
|
||||||
} else if( key == "environment.sky" ) {
|
} else if( key == "environment.sky" ) {
|
||||||
FastColour col = ParseWomColour( value, WorldEnv.DefaultSkyColour );
|
FastColour col = ParseWomColour( value, WorldEnv.DefaultSkyColour );
|
||||||
game.World.Env.SetSkyColour( col );
|
game.World.Env.SetSkyColour( col );
|
||||||
} else if( key == "environment.fog" ) {
|
} else if( key == "environment.fog" ) {
|
||||||
FastColour col = ParseWomColour( value, WorldEnv.DefaultFogColour );
|
FastColour col = ParseWomColour( value, WorldEnv.DefaultFogColour );
|
||||||
game.World.Env.SetFogColour( col );
|
game.World.Env.SetFogColour( col );
|
||||||
} else if( key == "environment.level" ) {
|
} else if( key == "environment.level" ) {
|
||||||
int waterLevel = 0;
|
int waterLevel = 0;
|
||||||
if( Int32.TryParse( value, out waterLevel ) )
|
if( Int32.TryParse( value, out waterLevel ) )
|
||||||
game.World.Env.SetEdgeLevel( waterLevel );
|
game.World.Env.SetEdgeLevel( waterLevel );
|
||||||
} else if( key == "user.detail" && !cpe.useMessageTypes ) {
|
} else if( key == "user.detail" && !cpe.useMessageTypes ) {
|
||||||
game.Chat.Add( value, MessageType.Status2 );
|
game.Chat.Add( value, MessageType.Status2 );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadWomConfigurationAsync() {
|
void ReadWomConfigAsync() {
|
||||||
string host = ServerMotd.Substring( ServerMotd.IndexOf( "cfg=" ) + 4 );
|
string host = ServerMotd.Substring( ServerMotd.IndexOf( "cfg=" ) + 4 );
|
||||||
string url = "http://" + host;
|
string url = "http://" + host;
|
||||||
url = url.Replace( "$U", game.Username );
|
url = url.Replace( "$U", game.Username );
|
||||||
|
|
||||||
// NOTE: this (should, I did test this) ensure that if the user quickly changes to a
|
// NOTE: this (should, I did test this) ensure that if the user quickly changes to a
|
||||||
// different world, the environment settings from the last world are not loaded in the
|
// different world, the environment settings from the last world are not loaded in the
|
||||||
// new world if the async 'get request' didn't complete before the new world was loaded.
|
// new world if the async 'get request' didn't complete before the new world was loaded.
|
||||||
@ -70,5 +67,23 @@ namespace ClassicalSharp.Network {
|
|||||||
int argb;
|
int argb;
|
||||||
return Int32.TryParse( value, out argb ) ? new FastColour( argb ) : defaultCol;
|
return Int32.TryParse( value, out argb ) ? new FastColour( argb ) : defaultCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string ReadLine(ref int start, string value) {
|
||||||
|
if (start == -1) return null;
|
||||||
|
for (int i = start; i < value.Length; i++) {
|
||||||
|
char c = value[i];
|
||||||
|
if (c != '\r' && c != '\n')) continue;
|
||||||
|
|
||||||
|
string line = value.Substring(start, i - start);
|
||||||
|
start = i + 1;
|
||||||
|
if (c == '\r' && start < value.Length && value[start] == '\n')
|
||||||
|
start++;
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
string last = value.Substring(start);
|
||||||
|
start = -1;
|
||||||
|
return last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -67,7 +67,7 @@ namespace ClassicalSharp.Network {
|
|||||||
|
|
||||||
public override void Tick( ScheduledTask task ) {
|
public override void Tick( ScheduledTask task ) {
|
||||||
if( Disconnected ) return;
|
if( Disconnected ) return;
|
||||||
if( (DateTime.UtcNow - lastPacket).TotalSeconds >= 20 )
|
if( (DateTime.UtcNow - lastPacket).TotalSeconds >= 30 )
|
||||||
CheckDisconnection( task.Interval );
|
CheckDisconnection( task.Interval );
|
||||||
if( Disconnected ) return;
|
if( Disconnected ) return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user