Browse Source

Reduce nesting for OnClientDisconnect

nosoop 3 years ago
parent
commit
09351d9bb8
1 changed files with 14 additions and 16 deletions
  1. 14 16
      scripting/simple-chatprocessor.sp

+ 14 - 16
scripting/simple-chatprocessor.sp

@@ -71,26 +71,24 @@ public void OnClientPutInServer(int client) {
 }
 
 public void OnClientDisconnect(int client) {
-	if (g_QueuedMessages[client]) {
-		if (g_QueuedMessages[client].Size > 0) {
-			// delete remaining queued messages, don't bother sending
-			StringMapSnapshot messages = g_QueuedMessages[client].Snapshot();
+	if (g_QueuedMessages[client] && g_QueuedMessages[client].Size > 0) {
+		// delete remaining queued messages, don't bother sending
+		StringMapSnapshot messages = g_QueuedMessages[client].Snapshot();
+		
+		for (int m = 0; m < messages.Length; m++) {
+			char packedMessage[192];
+			messages.GetKey(m, packedMessage, sizeof(packedMessage));
 			
-			for (int m = 0; m < messages.Length; m++) {
-				char packedMessage[192];
-				messages.GetKey(m, packedMessage, sizeof(packedMessage));
-				
-				ArrayList clientList;
-				g_QueuedMessages[client].GetValue(packedMessage, clientList);
-				
-				delete clientList;
-			}
-			delete messages;
+			ArrayList clientList;
+			g_QueuedMessages[client].GetValue(packedMessage, clientList);
 			
-			g_QueuedMessages[client].Clear();
+			delete clientList;
 		}
-		delete g_QueuedMessages[client];
+		delete messages;
+		
+		g_QueuedMessages[client].Clear();
 	}
+	delete g_QueuedMessages[client];
 }
 
 public Action OnSayText2(UserMsg id, Handle buffer, const int[] clients, int nClients,