Add a SendLowPriority method, currently does nothing special.

This commit is contained in:
UnknownShadow200 2017-07-20 20:53:10 +10:00
parent cf578efa4f
commit fa7da22a43
7 changed files with 19 additions and 11 deletions

View File

@ -24,7 +24,7 @@ namespace MCGalaxy {
public static class BlockQueue {
public static int time = 100;
public static int blockupdates = 1000;
public static int blockupdates = 750;
static BufferedBlockSender bulkSender = new BufferedBlockSender();
public static void Loop(SchedulerTask task) {

View File

@ -79,7 +79,7 @@ namespace MCGalaxy {
}
}
public void Send(byte[] buffer, bool sync = false) { socket.Send(buffer, sync); }
public void Send(byte[] buffer, bool sync = false) { Socket.Send(buffer, sync); }
public static void MessageLines(Player p, IEnumerable<string> lines) {
foreach (string line in lines)
@ -289,11 +289,11 @@ namespace MCGalaxy {
}
buffer[7] = raw;
Send(buffer);
Socket.SendLowPriority(buffer);
}
internal void CloseSocket() {
socket.Close();
Socket.Close();
RemoveFromPending();
}
}

View File

@ -35,6 +35,9 @@ namespace MCGalaxy.Network {
/// <summary> Sends a block of data, either synchronously or asynchronously. </summary>
void Send(byte[] buffer, bool sync = false);
/// <summary> Sends a block of low-priority data, either synchronously or asynchronously. </summary>
void SendLowPriority(byte[] buffer, bool sync = false);
/// <summary> Closes this network socket. </summary>
void Close();
}

View File

@ -100,6 +100,11 @@ namespace MCGalaxy.Network {
}
}
// TODO: do this seprately
public void SendLowPriority(byte[] buffer, bool sync = false) {
Send(buffer, sync);
}
static void SendCallback(IAsyncResult result) {
// TODO: call EndSend, need to check if all data was sent or not!
/*TcpSocket s = (TcpSocket)result.AsyncState;

View File

@ -73,7 +73,7 @@ namespace MCGalaxy.Network {
if (p.level != level) continue;
byte[] packet = MakePacket(p, ref bulk, ref normal,
ref noBlockDefs, ref original);
p.Send(packet);
p.Socket.SendLowPriority(packet);
}
}
@ -81,7 +81,7 @@ namespace MCGalaxy.Network {
byte[] bulk = null, normal = null, noBlockDefs = null, original = null;
byte[] packet = MakePacket(player, ref bulk, ref normal,
ref noBlockDefs, ref original);
player.Send(packet);
player.Socket.SendLowPriority(packet);
}
#region Packet construction

View File

@ -53,7 +53,7 @@ namespace MCGalaxy {
public string truename;
internal bool dontmindme = false;
INetworkSocket socket;
public INetworkSocket Socket;
public PingList Ping = new PingList();
public DateTime LastAction, AFKCooldown;

View File

@ -51,8 +51,8 @@ namespace MCGalaxy {
public Player(Socket s) {
spamChecker = new SpamChecker(this);
try {
socket = new TcpSocket(this, s);
ip = socket.RemoteIP;
Socket = new TcpSocket(this, s);
ip = Socket.RemoteIP;
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
Logger.Log(LogType.UserActivity, ip + " connected to the server.");
@ -60,7 +60,7 @@ namespace MCGalaxy {
BlockBindings[i] = ExtBlock.FromRaw((byte)i);
}
socket.ReceiveNextAsync();
Socket.ReceiveNextAsync();
connections.Add(this);
}
catch ( Exception e ) { Leave("Login failed!"); Logger.LogError(e); }
@ -276,7 +276,7 @@ namespace MCGalaxy {
//Umm...fixed?
if (name == "") {
if (socket != null) CloseSocket();
if (Socket != null) CloseSocket();
connections.Remove(this);
disconnected = true;
return;