317 |
|
|
318 |
} |
} |
319 |
|
|
320 |
|
int DoLeaveRoom(int p, int r) |
321 |
|
{ |
322 |
|
// lookup room |
323 |
|
std::map<int, room>::iterator rmi = rarray.find(r); |
324 |
|
if(rmi == rarray.end()) return COM_NOSUCHROOM; |
325 |
|
room& rm = rmi->second; |
326 |
|
|
327 |
|
// only occupants can leave |
328 |
|
std::map<int, occupant>::iterator res = rm.occupants.find(p); |
329 |
|
if(res == rm.occupants.end()) return COM_NOTINROOM; |
330 |
|
rm.occupants.erase(res); |
331 |
|
|
332 |
|
//delete any open posted games--should only be one, but |
333 |
|
//let's think ahead |
334 |
|
std::map<int, open_game>::iterator ogi = |
335 |
|
rm.open_games.begin(); |
336 |
|
|
337 |
|
while(ogi != rm.open_games.end()) |
338 |
|
if(ogi->second.inviter == p) |
339 |
|
rm.open_games.erase(ogi++); |
340 |
|
else |
341 |
|
++ogi; |
342 |
|
|
343 |
|
//delete any open challenges |
344 |
|
std::map<int, open_challenge>::iterator oci = |
345 |
|
rm.open_challenges.begin(); |
346 |
|
|
347 |
|
while(oci != rm.open_challenges.end()) |
348 |
|
if(oci->second.challenger == p) |
349 |
|
rm.open_challenges.erase(oci++); |
350 |
|
else |
351 |
|
++oci; |
352 |
|
|
353 |
|
|
354 |
|
std::string s = parray[p].login; |
355 |
|
ReplyOccupant(r, p, ROOM + Leave, s); |
356 |
|
s += "\n"; |
357 |
|
NotifyOccupants(r, ROOM + Leave, s, p); |
358 |
|
return COM_OK; |
359 |
|
} |
360 |
|
|
361 |
int clear_player_from_rooms(int p) |
int clear_player_from_rooms(int p) |
362 |
{ |
{ |
363 |
//check all the rooms for this player and send |
//check all the rooms for this player and send |
364 |
//a Leave notify to every there |
//a Leave notify to every there |
365 |
for(std::map<int, room>::iterator i = rarray.begin(); |
for(std::map<int, room>::iterator i = rarray.begin(); |
366 |
i != rarray.end(); ++i) { |
i != rarray.end(); ++i) { |
367 |
//this kind of replicates com_roomleave, but otherwise |
DoLeaveRoom(p, i->first); |
|
//I'd have to construct a fake param var here--which is worse? |
|
|
std::map<int, occupant>::iterator res = i->second.occupants.find(p); |
|
|
if(res != i->second.occupants.end()) { |
|
|
i->second.occupants.erase(res); |
|
|
std::string s = parray[p].login; |
|
|
s += "\n"; |
|
|
NotifyOccupants(i->first, ROOM + Leave, s, p); |
|
|
} |
|
368 |
} |
} |
369 |
} |
} |
370 |
|
|
662 |
int com_roomleave(int p, param_list param) |
int com_roomleave(int p, param_list param) |
663 |
{ |
{ |
664 |
int r = param[0].val.integer; |
int r = param[0].val.integer; |
665 |
// lookup room |
|
666 |
std::map<int, room>::iterator rmi = rarray.find(r); |
return DoLeaveRoom(p, r); |
|
if(rmi == rarray.end()) return COM_NOSUCHROOM; |
|
|
room& rm = rmi->second; |
|
|
// only occupants can leave |
|
|
std::map<int, occupant>::iterator res = rm.occupants.find(p); |
|
|
if(res == rm.occupants.end()) return COM_NOTINROOM; |
|
|
rm.occupants.erase(res); |
|
|
std::string s = parray[p].login; |
|
|
ReplyOccupant(r, p, ROOM + Leave, s); |
|
|
s += "\n"; |
|
|
NotifyOccupants(r, ROOM + Leave, s, p); |
|
|
return COM_OK; |
|
667 |
} |
} |
668 |
|
|
669 |
//admins can already silence people |
//admins can already silence people |