mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -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;
|
int mapSizeIndex, mapIndex;
|
||||||
byte[] mapSize = new byte[4], map;
|
byte[] mapSize = new byte[4], map;
|
||||||
FixedBufferStream gzippedMap;
|
FixedBufferStream gzippedMap;
|
||||||
|
DateTime lastPing;
|
||||||
|
|
||||||
void HandleHandshake() {
|
void HandleHandshake() {
|
||||||
byte protocolVer = reader.ReadUInt8();
|
byte protocolVer = reader.ReadUInt8();
|
||||||
@ -79,6 +80,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandlePing() {
|
void HandlePing() {
|
||||||
|
lastPing = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleLevelInit() {
|
void HandleLevelInit() {
|
||||||
|
@ -50,6 +50,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
MakeLoginPacket( game.Username, game.Mppass );
|
MakeLoginPacket( game.Username, game.Mppass );
|
||||||
SendPacket();
|
SendPacket();
|
||||||
|
lastPing = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
@ -102,7 +103,6 @@ namespace ClassicalSharp {
|
|||||||
bool Is304Status( WebException ex ) {
|
bool Is304Status( WebException ex ) {
|
||||||
if( ex == null || ex.Status != WebExceptionStatus.ProtocolError )
|
if( ex == null || ex.Status != WebExceptionStatus.ProtocolError )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
HttpWebResponse response = (HttpWebResponse)ex.Response;
|
HttpWebResponse response = (HttpWebResponse)ex.Response;
|
||||||
return response.StatusCode == HttpStatusCode.NotModified;
|
return response.StatusCode == HttpStatusCode.NotModified;
|
||||||
}
|
}
|
||||||
@ -110,6 +110,12 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public override void Tick( double delta ) {
|
public override void Tick( double delta ) {
|
||||||
if( Disconnected ) return;
|
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 {
|
try {
|
||||||
reader.ReadPendingData();
|
reader.ReadPendingData();
|
||||||
@ -164,9 +170,10 @@ namespace ClassicalSharp {
|
|||||||
try {
|
try {
|
||||||
writer.Send();
|
writer.Send();
|
||||||
} catch( IOException ex ) {
|
} catch( IOException ex ) {
|
||||||
ErrorHandler.LogError( "writing packets", ex );
|
// NOTE: Not immediately disconnecting, because it means we miss out on kick messages sometimes.
|
||||||
game.Disconnect( "&eLost connection to the server", "I/O Error while writing packets" );
|
//ErrorHandler.LogError( "writing packets", ex );
|
||||||
Dispose();
|
//game.Disconnect( "&eLost connection to the server", "I/O Error while writing packets" );
|
||||||
|
//Dispose();
|
||||||
writer.index = 0;
|
writer.index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user