diff --git a/MCGalaxy/Network/Socket/TcpSocket.cs b/MCGalaxy/Network/Socket/TcpSocket.cs
index 0718e2d23..fad6a16cf 100644
--- a/MCGalaxy/Network/Socket/TcpSocket.cs
+++ b/MCGalaxy/Network/Socket/TcpSocket.cs
@@ -33,12 +33,12 @@ namespace MCGalaxy.Network {
get { return ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(); }
}
- static AsyncCallback recvCallback = new AsyncCallback(Receive);
+ static AsyncCallback recvCallback = new AsyncCallback(ReceiveCallback);
public void ReceiveNextAsync() {
socket.BeginReceive(tempbuffer, 0, tempbuffer.Length, SocketFlags.None, recvCallback, this);
}
- static void Receive(IAsyncResult result) {
+ static void ReceiveCallback(IAsyncResult result) {
TcpSocket s = (TcpSocket)result.AsyncState;
Player p = s.player;
if (p.disconnected) return;
@@ -73,15 +73,17 @@ namespace MCGalaxy.Network {
}
}
+
+ static AsyncCallback sendCallback = new AsyncCallback(SendCallback);
public void Send(byte[] buffer, bool sync = false) {
// Abort if socket has been closed
if (player.disconnected || !socket.Connected) return;
-
+
try {
if (sync)
socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
else
- socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, delegate(IAsyncResult result) { }, null);
+ socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, sendCallback, this);
buffer = null;
} catch (SocketException e) {
buffer = null;
@@ -95,6 +97,22 @@ namespace MCGalaxy.Network {
}
}
+ static void SendCallback(IAsyncResult result) {
+ TcpSocket s = (TcpSocket)result.AsyncState;
+
+ try {
+ int sent = s.socket.EndSend(result);
+ } catch (SocketException e) {
+ s.player.Disconnect();
+ #if DEBUG
+ Server.ErrorLog(e);
+ #endif
+ } catch (ObjectDisposedException) {
+ // socket was already closed by another thread.
+ }
+ }
+
+
public void Close() {
// Try to close the socket.
// Sometimes its already closed so these lines will cause an error
diff --git a/MCGalaxy/Player/Group/Group.cs b/MCGalaxy/Player/Group/Group.cs
index c7ccdafdf..bca2137ec 100644
--- a/MCGalaxy/Player/Group/Group.cs
+++ b/MCGalaxy/Player/Group/Group.cs
@@ -242,12 +242,6 @@ namespace MCGalaxy {
public static Group findPermInt(int Perm) {
return GroupList.Find(grp => (int)grp.Permission == Perm);
}
-
-
- /// Get the group name that player /playerName/ is in
- /// The player Name
- /// The group name
- public static string findPlayer(string name) { return findPlayerGroup(name).name; }
/// Find the group object that the player /playerName/ is in
/// The player name
diff --git a/MCGalaxy/Player/Group/GroupProperties.cs b/MCGalaxy/Player/Group/GroupProperties.cs
index 1d22cad2a..25ed3238f 100644
--- a/MCGalaxy/Player/Group/GroupProperties.cs
+++ b/MCGalaxy/Player/Group/GroupProperties.cs
@@ -59,7 +59,7 @@ namespace MCGalaxy {
} if (perm > 119 || perm < -50) {
Server.s.Log("Permission must be between -50 and 119 for ranks");
grp = null;
- } else if (Group.GroupList.Find(g => g.Permission == (LevelPermission)perm) == null) {
+ } else if (Group.findPermInt(perm) == null) {
grp.Permission = (LevelPermission)perm;
} else {
Server.s.Log("Cannot have 2 ranks set at permission level " + value);