Browse Source

Replaced clif_countusers() with a more efficient alternative (thanks to the fact that pc_db now only holds fully authed players only).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12339 54d463be-8e91-2dee-dedb-b68131a5f0ec
ultramage 17 years ago
parent
commit
a5f7761c0f
6 changed files with 20 additions and 31 deletions
  1. 1 9
      src/map/chrif.c
  2. 0 17
      src/map/clif.c
  3. 0 1
      src/map/clif.h
  4. 17 3
      src/map/map.c
  5. 1 0
      src/map/map.h
  6. 1 1
      src/map/pc.c

+ 1 - 9
src/map/chrif.c

@@ -1442,19 +1442,11 @@ int ping_char_server(int tid, unsigned int tick, int id, int data)
 // unused
 int send_usercount_tochar(int tid, unsigned int tick, int id, int data)
 {
-	int count = 0;
-	struct s_mapiterator* iter;
-
 	chrif_check(-1);
 
-	iter = mapit_getallusers();
-	for( mapit_first(iter); mapit_exists(iter); mapit_next(iter) )
-		count++;
-	mapit_free(iter);
-
 	WFIFOHEAD(char_fd,4);
 	WFIFOW(char_fd,0) = 0x2afe;
-	WFIFOW(char_fd,2) = count;
+	WFIFOW(char_fd,2) = map_usercount();
 	WFIFOSET(char_fd,4);
 	return 0;
 }

+ 0 - 17
src/map/clif.c

@@ -164,23 +164,6 @@ uint16 clif_getport(void)
 	return map_port;
 }
 
-/*==========================================
- * Counts connected players.
- *------------------------------------------*/
-int clif_countusers(void)
-{
-	int users = 0, i;
-	struct map_session_data *sd;
-
-	for(i = 0; i < fd_max; i++) {
-		if (session[i] && session[i]->func_parse == clif_parse &&
-			(sd = (struct map_session_data*)session[i]->session_data) &&
-		  	sd->state.active && !(battle_config.hide_GM_session && pc_isGM(sd)))
-			users++;
-	}
-	return users;
-}
-
 /*==========================================
  * ‘S‚Ä‚Ìclient‚ɑ΂µ‚Äfunc()ŽÀ�s
  *------------------------------------------*/

+ 0 - 1
src/map/clif.h

@@ -91,7 +91,6 @@ void clif_setport(uint16 port);
 uint32 clif_getip(void);
 uint32 clif_refresh_ip(void);
 uint16 clif_getport(void);
-int clif_countusers(void);
 void clif_setwaitclose(int);
 
 int clif_authok(struct map_session_data *);

+ 17 - 3
src/map/map.c

@@ -170,14 +170,28 @@ void map_setusers(int users)
 	map_users = users;
 }
 
-/*==========================================
- * 全map鯖?計での接??取得 (/wへの?答用)
- *------------------------------------------*/
 int map_getusers(void)
 {
 	return map_users;
 }
 
+/*==========================================
+ * server player count (this mapserver only)
+ *------------------------------------------*/
+int map_usercount(void)
+{
+/*
+	int count = 0;
+	struct s_mapiterator* iter = mapit_getallusers();
+	for( mapit_first(iter); mapit_exists(iter); mapit_next(iter) )
+		count++;
+	mapit_free(iter);
+	return count;
+*/
+	// since pc_db now only holds fully authed players, this approach is equivalent:
+	return pc_db->size(pc_db);
+}
+
 //
 // block削除の安全性確保?理
 //

+ 1 - 0
src/map/map.h

@@ -1269,6 +1269,7 @@ extern char wisp_server_name[];
 // ŽI‘S‘Ì�î•ñ
 void map_setusers(int);
 int map_getusers(void);
+int map_usercount(void);
 // block�í�œŠÖ˜A
 int map_freeblock(struct block_list *bl);
 int map_freeblock_lock(void);

+ 1 - 1
src/map/pc.c

@@ -6900,7 +6900,7 @@ int pc_autosave(int tid,unsigned int tick,int id,int data)
 	}
 	mapit_free(iter);
 
-	interval = autosave_interval/(clif_countusers()+1);
+	interval = autosave_interval/(map_usercount()+1);
 	if(interval < minsave_interval)
 		interval = minsave_interval;
 	add_timer(gettick()+interval,pc_autosave,0,0);