summaryrefslogtreecommitdiff
path: root/src/map/map.c
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2008-12-12 12:23:58 -0700
committerFate <fate-tmw@googlemail.com>2008-12-12 12:23:58 -0700
commit9537c3f0086c8985d84eb0fa5823e8be185beada (patch)
tree4338d77c0bac1f9c3807d4fca6acca873ec73916 /src/map/map.c
parentdbd6ed3452751d45b866572fd42784bc8e7c8161 (diff)
downloadtmwa-9537c3f0086c8985d84eb0fa5823e8be185beada.tar.gz
tmwa-9537c3f0086c8985d84eb0fa5823e8be185beada.tar.bz2
tmwa-9537c3f0086c8985d84eb0fa5823e8be185beada.tar.xz
tmwa-9537c3f0086c8985d84eb0fa5823e8be185beada.zip
Added @hugo and @linus commands for iterating over logged-in players
Diffstat (limited to 'src/map/map.c')
-rw-r--r--src/map/map.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 3db293c..6ca1bd4 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1145,6 +1145,74 @@ char * map_charid2nick(int id) {
return p->nick;
}
+/*========================================*/
+/* [Fate] Operations to iterate over active map sessions */
+
+static struct map_session_data *
+map_get_session(int i)
+{
+ struct map_session_data *d;
+
+ if (i >= 0 && i < fd_max
+ && session[i] && (d = session[i]->session_data)
+ && d->state.auth)
+ return d;
+
+ return NULL;
+}
+
+static struct map_session_data *
+map_get_session_forward(int start)
+{
+ int i;
+ for (i = start; i < fd_max; i++) {
+ struct map_session_data *d = map_get_session(i);
+ if (d)
+ return d;
+ }
+
+ return NULL;
+}
+
+static struct map_session_data *
+map_get_session_backward(int start)
+{
+ int i;
+ for (i = start; i >= 0; i--) {
+ struct map_session_data *d = map_get_session(i);
+ if (d)
+ return d;
+ }
+
+ return NULL;
+}
+
+struct map_session_data *
+map_get_first_session()
+{
+ return map_get_session_forward(0);
+}
+
+struct map_session_data *
+map_get_next_session(struct map_session_data *d)
+{
+ return map_get_session_forward(d->fd + 1);
+}
+
+struct map_session_data *
+map_get_last_session()
+{
+ return map_get_session_backward(fd_max);
+}
+
+struct map_session_data *
+map_get_prev_session(struct map_session_data *d)
+{
+ return map_get_session_backward(d->fd - 1);
+}
+
+
+
/*==========================================
* Search session data from a nick name