mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Don't immediately disconnect on first failed write, thus ensuring all kick messages are shown.
This commit is contained in:
parent
09757d6316
commit
140ed90269
@ -68,6 +68,7 @@ namespace ClassicalSharp {
|
||||
int mapSizeIndex, mapIndex;
|
||||
byte[] mapSize = new byte[4], map;
|
||||
FixedBufferStream gzippedMap;
|
||||
DateTime lastPing;
|
||||
|
||||
void HandleHandshake() {
|
||||
byte protocolVer = reader.ReadUInt8();
|
||||
@ -77,8 +78,9 @@ namespace ClassicalSharp {
|
||||
receivedFirstPosition = false;
|
||||
game.LocalPlayer.ParseHackFlags( ServerName, ServerMotd );
|
||||
}
|
||||
|
||||
|
||||
void HandlePing() {
|
||||
lastPing = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
void HandleLevelInit() {
|
||||
|
@ -50,6 +50,7 @@ namespace ClassicalSharp {
|
||||
|
||||
MakeLoginPacket( game.Username, game.Mppass );
|
||||
SendPacket();
|
||||
lastPing = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
@ -101,8 +102,7 @@ namespace ClassicalSharp {
|
||||
|
||||
bool Is304Status( WebException ex ) {
|
||||
if( ex == null || ex.Status != WebExceptionStatus.ProtocolError )
|
||||
return false;
|
||||
|
||||
return false;
|
||||
HttpWebResponse response = (HttpWebResponse)ex.Response;
|
||||
return response.StatusCode == HttpStatusCode.NotModified;
|
||||
}
|
||||
@ -110,6 +110,12 @@ namespace ClassicalSharp {
|
||||
|
||||
public override void Tick( double delta ) {
|
||||
if( Disconnected ) return;
|
||||
if( (DateTime.UtcNow - lastPing).TotalSeconds >= 15 ) {
|
||||
game.Disconnect( "&eDisconnected from the server",
|
||||
"No ping packet received for over 15 seconds." );
|
||||
Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
reader.ReadPendingData();
|
||||
@ -164,9 +170,10 @@ namespace ClassicalSharp {
|
||||
try {
|
||||
writer.Send();
|
||||
} catch( IOException ex ) {
|
||||
ErrorHandler.LogError( "writing packets", ex );
|
||||
game.Disconnect( "&eLost connection to the server", "I/O Error while writing packets" );
|
||||
Dispose();
|
||||
// NOTE: Not immediately disconnecting, because it means we miss out on kick messages sometimes.
|
||||
//ErrorHandler.LogError( "writing packets", ex );
|
||||
//game.Disconnect( "&eLost connection to the server", "I/O Error while writing packets" );
|
||||
//Dispose();
|
||||
writer.index = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user