5 * Free a session's march list
7 void free_march_list(wcsession * wcf) {
10 while (wcf->march != NULL) {
11 mptr = wcf->march->next;
20 * remove a room from the march list
22 void remove_march(const StrBuf * aaa) {
23 struct march *mptr, *mptr2;
25 if (WC->march == NULL)
28 if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
29 mptr = WC->march->next;
35 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
36 if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
37 mptr2->next = mptr->next;
50 * \brief Locate the room on the march list which we most want to go to.
52 * is measured given a "weight" of preference based on various factors.
53 * \param desired_floor the room number on the citadel server
54 * \return the roomname
56 char *pop_march(int desired_floor) {
57 static char TheRoom[128];
60 struct march *mptr = NULL;
62 strcpy(TheRoom, "_BASEROOM_");
63 if (WC->march == NULL)
66 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
68 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
69 weight = weight + 10000;
70 if (mptr->march_floor == desired_floor)
71 weight = weight + 5000;
73 weight = weight + ((128 - (mptr->march_floor)) * 128);
74 weight = weight + (128 - (mptr->march_order));
76 if (weight > TheWeight) {
78 strcpy(TheRoom, mptr->march_name);
81 TheFloor = mptr->march_floor;
82 TheOrder = mptr->march_order;
92 * Goto next room having unread messages.
94 * We want to skip over rooms that the user has already been to, and take the
95 * user back to the lobby when done. The room we end up in is placed in
96 * newroom - which is set to 0 (the lobby) initially.
97 * We start the search in the current room rather than the beginning to prevent
98 * two or more concurrent users from dragging each other back to the same room.
100 void gotonext(void) {
102 struct march *mptr = NULL;
103 struct march *mptr2 = NULL;
109 * First check to see if the march-mode list is already allocated.
110 * If it is, pop the first room off the list and go there.
112 if (havebstr("startmsg")) {
113 readloop(readnew, eUseDefault);
117 if (WC->march == NULL) {
119 serv_getln(buf, sizeof buf);
121 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
122 if (IsEmptyStr(buf)) {
125 if (ELoop % 100 == 0)
130 extract_token(room_name, buf, 0, '|', sizeof room_name);
131 if (strcasecmp(room_name, ChrPtr(WC->CurRoom.name))) {
132 mptr = (struct march *) malloc(sizeof(struct march));
134 safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
135 mptr->march_floor = extract_int(buf, 2);
136 mptr->march_order = extract_int(buf, 3);
137 if (WC->march == NULL)
146 * add _BASEROOM_ to the end of the march list, so the user will end up
147 * in the system base room (usually the Lobby>) at the end of the loop
149 mptr = (struct march *) malloc(sizeof(struct march));
151 mptr->march_order = 0;
152 mptr->march_floor = 0;
153 strcpy(mptr->march_name, "_BASEROOM_");
154 if (WC->march == NULL) {
159 while (mptr2->next != NULL)
164 * ...and remove the room we're currently in, so a <G>oto doesn't make us
165 * walk around in circles
167 remove_march(WC->CurRoom.name);
169 if (WC->march != NULL) {
170 next_room = NewStrBufPlain(pop_march(-1), -1); /*TODO: migrate march to strbuf */
171 putlbstr("gotonext", 1);
174 next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
178 smart_goto(next_room);
179 FreeStrBuf(&next_room);
183 * un-goto the previous room
188 if (havebstr("startmsg")) {
189 readloop(readnew, eUseDefault);
193 if (!strcmp(WC->ugname, "")) {
194 smart_goto(WC->CurRoom.name);
197 serv_printf("GOTO %s", WC->ugname);
199 StrBuf_ServGetln(Buf);
200 if (GetServerStatus(Buf, NULL) != 2) {
201 smart_goto(WC->CurRoom.name);
205 if (WC->uglsn >= 0L) {
206 serv_printf("SLRP %ld", WC->uglsn);
207 StrBuf_ServGetln(Buf);
210 StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
211 strcpy(WC->ugname, "");
218 void tmplput_ungoto(StrBuf * Target, WCTemplputParams * TP) {
221 if ((WCC != NULL) && (!IsEmptyStr(WCC->ugname)))
222 StrBufAppendBufPlain(Target, WCC->ugname, -1, 0);
225 void _gotonext(void) {
233 int ConditionalHaveUngoto(StrBuf * Target, WCTemplputParams * TP) {
236 return ((WCC != NULL) && (!IsEmptyStr(WCC->ugname)) && (strcasecmp(WCC->ugname, ChrPtr(WCC->CurRoom.name)) == 0));
240 void InitModule_MARCHLIST(void) {
241 RegisterConditional("COND:UNGOTO", 0, ConditionalHaveUngoto, CTX_NONE);
242 RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, NULL, CTX_NONE);
244 WebcitAddUrlHandler(HKEY("gotonext"), "", 0, _gotonext, NEED_URL);
245 WebcitAddUrlHandler(HKEY("skip"), "", 0, gotonext, NEED_URL);
246 WebcitAddUrlHandler(HKEY("ungoto"), "", 0, ungoto, NEED_URL);