]>
jfr.im git - irc/gameservirc.git/blob - gameserv/messages.cpp
e996471929d48f923339460f7f72757549be0276
1 /* This file contains only functions related to sending messages over the
16 void raw(const char *fmt
, ...)
21 input
= new char[2048];
22 buffer
= new char[1024];
24 vsnprintf(buffer
, 1024, fmt
, args
);
27 memset(input
, 0, sizeof(input
)); // Initialize to NULL
28 for (t
= buffer
; *t
; t
++)
33 case 'S': sprintf(input
, "%s%s", input
, s_GameServ
); break;
38 sprintf(input
, "%s%c", input
, *t
);
43 log("Input: %s", input
);
46 sprintf(input
, "%s%s", input
, "\r\n");
47 sock_puts(sock
, input
);
51 /* Send a NOTICE from the given source to the given nick. */
53 void notice(const char *source
, const char *dest
, const char *fmt
, ...)
59 commanduse
= new char[16];
63 strcpy(commanduse
, "P");
65 strcpy(commanduse
, "O");
69 strcpy(commanduse
, "PRIVMSG");
71 strcpy(commanduse
, "NOTICE");
77 input
= new char[2048];
78 buffer
= new char[1024];
80 vsnprintf(buffer
, 1024, fmt
, args
);
88 sprintf(input
, ":%s %s %s :", source
, commanduse
, dest
);
90 sprintf(input
, "%s %s %s :", gsnum
, commanduse
, dest
);
98 sprintf(input
, ":%s %s %s :", source
, commanduse
, dest
);
100 sprintf(input
, "%s %s %s :", gsnum
, commanduse
, dest
);
103 log("buffer: %s", buffer
);
104 for (t
= buffer
; *t
; t
++)
110 sprintf(input
, "%s%s", input
, s_GameServ
);
115 sprintf(input
, "%s%c", input
, *t
);
120 log("Input: %s", input
);
122 sprintf(input
, "%s%s", input
, "\r\n");
123 sock_puts(sock
, input
);
124 delete [] commanduse
;
129 void showstats(const char *u
, const char *nick
)
131 aClient
*sender
= find(u
);
138 if (!(p
= findplayer(nick
)))
140 notice(s_GameServ
, u
, "%s not found", nick
);
144 notice(s_GameServ
, sender
->getNick(), "Stats for %s:", p
->getName().c_str());
146 sprintf(buf
, "Experience: %ld", p
->getExp());
147 space
= spaces(strlen(buf
), " ");
148 notice(s_GameServ
, sender
->getNick(), "%s%sLevel: %d", buf
, space
,
152 sprintf(buf
, "Gold: %ld", p
->getGold());
153 space
= spaces(strlen(buf
), " ");
154 notice(s_GameServ
, sender
->getNick(), "%s%sGold in Bank: %ld", buf
, space
, p
->getBank());
157 notice(s_GameServ
, sender
->getNick(), "Hit Points: %d of %d", p
->getHP(),
160 sprintf(buf
, "Strength: %d", p
->getStrength());
161 space
= spaces(strlen(buf
), " ");
162 notice(s_GameServ
, sender
->getNick(), "%s%sDefense: %d",
163 buf
, space
, p
->getDefense());
166 sprintf(buf
, "Armor: %s", (p
->getArmor() ? p
->getArmor()->getName().c_str() : "Nothing"));
167 space
= spaces(strlen(buf
), " ");
169 notice(s_GameServ
, sender
->getNick(), "%s%sWeapon: %s", buf
, space
,
170 (p
->getWeapon() ? p
->getWeapon()->getName().c_str() : "Fists"));
174 sprintf(buf
, "Forest Fights: %d", p
->getForestFights());
175 space
= spaces(strlen(buf
), " ");
176 notice(s_GameServ
, sender
->getNick(), "%s%sPlayer Fights: %d", buf
, space
, p
->getPlayerFights());
178 if (p
->getClient() == sender
|| isAdmin(sender
))
180 showinventory(p
, sender
);
187 void display_monster(char *u
)
191 aClient
*user
= find(u
);
192 Player
*ni
= user
->stats
;
194 notice(s_GameServ
, u
, "Your Hitpoints: \ 2%d\ 2", ni
->getHP());
195 notice(s_GameServ
, u
, "%s's Hitpoints: \ 2%d\ 2", ni
->getMonster()->name
.c_str(), ni
->getMonster()->hp
);
196 notice(s_GameServ
, u
, "Here are your commands:");
197 notice(s_GameServ
, u
, "/msg <S attack");
198 notice(s_GameServ
, u
, "/msg <S run");
199 notice(s_GameServ
, u
, "What will you do?");
203 void display_players(char *u
)
206 if (!(user
= find(u
)))
208 log("Fatal error in display_players(): Couldn't find %s", u
);
211 display_players(user
);
214 void display_players(aClient
*user
)
216 char *u
= user
->getNick();
217 if (is_playing(user
) && player_fight(user
))
219 aClient
*battle
= user
->stats
->getBattle();
220 notice(s_GameServ
, u
, "Your Hitpoints: \ 2%d\ 2", user
->stats
->getHP());
221 notice(s_GameServ
, u
, "%s's Hitpoints: \ 2%d\ 2", battle
->stats
->getName().c_str(), battle
->stats
->getHP());
222 notice(s_GameServ
, u
, "Here are your commands:");
223 notice(s_GameServ
, u
, "/msg <S attack");
224 notice(s_GameServ
, u
, "/msg <S run");
225 notice(s_GameServ
, u
, "What will you do?");
229 void showinventory(Player
*from
, aClient
*to
)
237 nick
= to
->getNick();
239 if (from
->inventory
->isEmpty())
241 notice(s_GameServ
, nick
, "You aren't carrying anything");
245 list
<itemContainer
> *items
;
246 items
= from
->inventory
->getItems();
248 list
<itemContainer
>::iterator item_iter
, item_iter2
;
249 item_iter
= items
->begin();
251 notice(s_GameServ
, nick
, "Inventory for %s:", from
->getName().c_str());
253 while (item_iter
!= items
->end())
255 // Display a list of counted items so as not to show an extra line for duplicate items
257 item_iter2
= item_iter
;
258 while (item_iter
!= items
->end() && (*item_iter
) == (*item_iter2
))
260 if ((*item_iter
) == (*item_iter2
))
270 notice(s_GameServ
, nick
, "%ld.) %s (%ld)", (*item_iter2
).getItem()->getID(), (*item_iter2
).getItem()->getName().c_str(), count
);
275 void showTavern(aClient
*user
)
278 list
<tavernItem
>::iterator item_iterator
;
286 item_iterator
= tavern
.begin();
289 notice(s_GameServ
, user
->getNick(), "Tavern is empty");
293 while (item_iterator
!= tavern
.end())
295 if (p
->getLevel() < (*item_iterator
).getLevel())
300 tempItem
= (*item_iterator
).getItem();
301 notice(s_GameServ
, user
->getNick(), "%d. %s for %ld gold", tempItem
->getID(), tempItem
->getName().c_str(), tempItem
->price());
306 void showBankBalance(const char *u
)
311 if (!(user
= find(u
)))
319 notice(s_GameServ
, u
, "Account Balance: %ld Gold On hand: %ld", p
->getBank(), p
->getGold());
322 void display_help(char *u
, char *file
)
329 infile
.open("helpfiles/help");
332 log("Error opening helpfiles/help");
333 notice(s_GameServ
, u
, "Error opening helpfiles/help");
336 buf
= new char[1024];
337 while(infile
.getline(buf
, 1024))
339 // Written this way, it will process <S in the helpfiles
340 // Instead of notice(s_GameServ, u, "%s", buf);
341 notice(s_GameServ
, u
, buf
);
345 aClient
*user
= find(u
);
346 if (user
&& isAdmin(user
))
347 display_help(u
, "admin_commands");
352 filename
= new char[strlen(file
) + 11];
353 strcpy(filename
, "helpfiles/");
354 strcat(filename
, file
);
356 for (unsigned int x
= 10; x
< strlen(filename
); x
++)
357 filename
[x
] = tolower(filename
[x
]);
359 infile
.open(filename
);
363 notice(s_GameServ
, u
, "No help for \ 2%s\ 2", file
);
366 buf
= new char[1024];
367 while(infile
.getline(buf
, 1024))
369 // Written this way, it will process <S in the helpfiles
370 // Instead of notice(s_GameServ, u, "%s", buf);
371 notice(s_GameServ
, u
, buf
);