5 * Free a session's march list
7 void free_march_list(wcsession *wcf)
11 while (wcf->march != NULL) {
12 mptr = wcf->march->next;
22 * remove a room from the march list
24 void remove_march(const StrBuf *aaa)
26 struct march *mptr, *mptr2;
28 if (WC->march == NULL)
31 if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
32 mptr = WC->march->next;
38 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
39 if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
40 mptr2->next = mptr->next;
52 * \brief Locate the room on the march list which we most want to go to.
54 * is measured given a "weight" of preference based on various factors.
55 * \param desired_floor the room number on the citadel server
56 * \return the roomname
58 char *pop_march(int desired_floor)
60 static char TheRoom[128];
63 struct march *mptr = NULL;
65 strcpy(TheRoom, "_BASEROOM_");
66 if (WC->march == NULL)
69 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
71 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
72 weight = weight + 10000;
73 if (mptr->march_floor == desired_floor)
74 weight = weight + 5000;
76 weight = weight + ((128 - (mptr->march_floor)) * 128);
77 weight = weight + (128 - (mptr->march_order));
79 if (weight > TheWeight) {
81 strcpy(TheRoom, mptr->march_name);
90 * Goto next room having unread messages.
92 * We want to skip over rooms that the user has already been to, and take the
93 * user back to the lobby when done. The room we end up in is placed in
94 * newroom - which is set to 0 (the lobby) initially.
95 * We start the search in the current room rather than the beginning to prevent
96 * two or more concurrent users from dragging each other back to the same room.
101 struct march *mptr = NULL;
102 struct march *mptr2 = NULL;
108 * First check to see if the march-mode list is already allocated.
109 * If it is, pop the first room off the list and go there.
111 if (havebstr("startmsg")) {
112 readloop(readnew, eUseDefault);
116 if (WC->march == NULL) {
118 serv_getln(buf, sizeof buf);
120 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
121 if (IsEmptyStr(buf)) {
124 if (ELoop % 100 == 0)
129 extract_token(room_name, buf, 0, '|', sizeof room_name);
130 if (strcasecmp(room_name, ChrPtr(WC->CurRoom.name))) {
131 mptr = (struct march *) malloc(sizeof(struct march));
133 safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
134 mptr->march_floor = extract_int(buf, 2);
135 mptr->march_order = extract_int(buf, 3);
136 if (WC->march == NULL)
145 * add _BASEROOM_ to the end of the march list, so the user will end up
146 * in the system base room (usually the Lobby>) at the end of the loop
148 mptr = (struct march *) malloc(sizeof(struct march));
150 mptr->march_order = 0;
151 mptr->march_floor = 0;
152 strcpy(mptr->march_name, "_BASEROOM_");
153 if (WC->march == NULL) {
157 while (mptr2->next != NULL)
162 * ...and remove the room we're currently in, so a <G>oto doesn't make us
163 * walk around in circles
165 remove_march(WC->CurRoom.name);
167 if (WC->march != NULL) {
168 next_room = NewStrBufPlain(pop_march(-1), -1);/*TODO: migrate march to strbuf */
170 next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
174 smart_goto(next_room);
175 FreeStrBuf(&next_room);
179 * un-goto the previous room
185 if (havebstr("startmsg")) {
186 readloop(readnew, eUseDefault);
190 if (!strcmp(WC->ugname, "")) {
191 smart_goto(WC->CurRoom.name);
194 serv_printf("GOTO %s", WC->ugname);
196 StrBuf_ServGetln(Buf);
197 if (GetServerStatus(Buf, NULL) != 2) {
198 smart_goto(WC->CurRoom.name);
202 if (WC->uglsn >= 0L) {
203 serv_printf("SLRP %ld", WC->uglsn);
204 StrBuf_ServGetln(Buf);
207 StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
208 strcpy(WC->ugname, "");
215 void _gotonext(void) {
222 smart_goto(sbstr("room"));
233 WebcitAddUrlHandler(HKEY("gotonext"), "", 0, _gotonext, NEED_URL);
234 WebcitAddUrlHandler(HKEY("skip"), "", 0, gotonext, NEED_URL);
235 WebcitAddUrlHandler(HKEY("ungoto"), "", 0, ungoto, NEED_URL);