mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-28 07:55:38 -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;
|
||||
|
||||
game.Gui.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ), false );
|
||||
if( ServerMotd.Contains( "cfg=" ) ) {
|
||||
ReadWomConfigurationAsync();
|
||||
}
|
||||
if( ServerMotd.Contains( "cfg=" ) && !game.PureClassic )
|
||||
ReadWomConfigAsync();
|
||||
receivedFirstPosition = false;
|
||||
gzipHeader = new GZipHeaderReader();
|
||||
|
||||
|
@ -2,10 +2,7 @@
|
||||
// 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
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using ClassicalSharp.Map;
|
||||
using ClassicalSharp.Network;
|
||||
|
||||
namespace ClassicalSharp.Network {
|
||||
|
||||
@ -24,14 +21,14 @@ namespace ClassicalSharp.Network {
|
||||
}
|
||||
|
||||
void ParseWomConfig( string page ) {
|
||||
using( StringReader reader = new StringReader( page ) ) {
|
||||
string line;
|
||||
while( ( line = reader.ReadLine() ) != null ) {
|
||||
int start = 0;
|
||||
while( (line = ReadLine( ref start, page )) != null ) {
|
||||
Utils.LogDebug( line );
|
||||
string[] parts = line.Split( new [] { '=' }, 2 );
|
||||
if( parts.Length < 2 ) continue;
|
||||
string key = parts[0].TrimEnd();
|
||||
string value = parts[1].TrimStart();
|
||||
int sepIndex = line.IndexOf('=');
|
||||
if( sepIndex == -1 ) continue;
|
||||
string key = line.Substring(0, sepIndex).TrimEnd();
|
||||
string value = line.Substring(sepIndex + 1).TrimStart();
|
||||
|
||||
if( key == "environment.cloud" ) {
|
||||
FastColour col = ParseWomColour( value, WorldEnv.DefaultCloudsColour );
|
||||
@ -51,12 +48,12 @@ namespace ClassicalSharp.Network {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReadWomConfigurationAsync() {
|
||||
void ReadWomConfigAsync() {
|
||||
string host = ServerMotd.Substring( ServerMotd.IndexOf( "cfg=" ) + 4 );
|
||||
string url = "http://" + host;
|
||||
url = url.Replace( "$U", game.Username );
|
||||
|
||||
// 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
|
||||
// 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;
|
||||
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 ) {
|
||||
if( Disconnected ) return;
|
||||
if( (DateTime.UtcNow - lastPacket).TotalSeconds >= 20 )
|
||||
if( (DateTime.UtcNow - lastPacket).TotalSeconds >= 30 )
|
||||
CheckDisconnection( task.Interval );
|
||||
if( Disconnected ) return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user