]> git.lizzy.rs Git - minetest.git/blob - src/clientiface.cpp
Replace std::list by std::vector into ClientMap::updateDrawList, Map::timerUpdate...
[minetest.git] / src / clientiface.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <sstream>
21
22 #include "clientiface.h"
23 #include "util/numeric.h"
24 #include "util/mathconstants.h"
25 #include "player.h"
26 #include "settings.h"
27 #include "mapblock.h"
28 #include "network/connection.h"
29 #include "environment.h"
30 #include "map.h"
31 #include "emerge.h"
32 #include "serverobject.h"              // TODO this is used for cleanup of only
33 #include "main.h"                      // for g_settings
34 #include "log.h"
35
36 const char *ClientInterface::statenames[] = {
37         "Invalid",
38         "Disconnecting",
39         "Denied",
40         "Created",
41         "InitSent",
42         "InitDone",
43         "DefinitionsSent",
44         "Active"
45 };
46
47
48
49 std::string ClientInterface::state2Name(ClientState state)
50 {
51         return statenames[state];
52 }
53
54 void RemoteClient::ResendBlockIfOnWire(v3s16 p)
55 {
56         // if this block is on wire, mark it for sending again as soon as possible
57         if (m_blocks_sending.find(p) != m_blocks_sending.end()) {
58                 SetBlockNotSent(p);
59         }
60 }
61
62 void RemoteClient::GetNextBlocks (
63                 ServerEnvironment *env,
64                 EmergeManager * emerge,
65                 float dtime,
66                 std::vector<PrioritySortedBlockTransfer> &dest)
67 {
68         DSTACK(__FUNCTION_NAME);
69
70
71         // Increment timers
72         m_nothing_to_send_pause_timer -= dtime;
73         m_nearest_unsent_reset_timer += dtime;
74
75         if(m_nothing_to_send_pause_timer >= 0)
76                 return;
77
78         Player *player = env->getPlayer(peer_id);
79         // This can happen sometimes; clients and players are not in perfect sync.
80         if(player == NULL)
81                 return;
82
83         // Won't send anything if already sending
84         if(m_blocks_sending.size() >= g_settings->getU16
85                         ("max_simultaneous_block_sends_per_client"))
86         {
87                 //infostream<<"Not sending any blocks, Queue full."<<std::endl;
88                 return;
89         }
90
91         v3f playerpos = player->getPosition();
92         v3f playerspeed = player->getSpeed();
93         v3f playerspeeddir(0,0,0);
94         if(playerspeed.getLength() > 1.0*BS)
95                 playerspeeddir = playerspeed / playerspeed.getLength();
96         // Predict to next block
97         v3f playerpos_predicted = playerpos + playerspeeddir*MAP_BLOCKSIZE*BS;
98
99         v3s16 center_nodepos = floatToInt(playerpos_predicted, BS);
100
101         v3s16 center = getNodeBlockPos(center_nodepos);
102
103         // Camera position and direction
104         v3f camera_pos = player->getEyePosition();
105         v3f camera_dir = v3f(0,0,1);
106         camera_dir.rotateYZBy(player->getPitch());
107         camera_dir.rotateXZBy(player->getYaw());
108
109         /*infostream<<"camera_dir=("<<camera_dir.X<<","<<camera_dir.Y<<","
110                         <<camera_dir.Z<<")"<<std::endl;*/
111
112         /*
113                 Get the starting value of the block finder radius.
114         */
115
116         if(m_last_center != center)
117         {
118                 m_nearest_unsent_d = 0;
119                 m_last_center = center;
120         }
121
122         /*infostream<<"m_nearest_unsent_reset_timer="
123                         <<m_nearest_unsent_reset_timer<<std::endl;*/
124
125         // Reset periodically to workaround for some bugs or stuff
126         if(m_nearest_unsent_reset_timer > 20.0)
127         {
128                 m_nearest_unsent_reset_timer = 0;
129                 m_nearest_unsent_d = 0;
130                 //infostream<<"Resetting m_nearest_unsent_d for "
131                 //              <<server->getPlayerName(peer_id)<<std::endl;
132         }
133
134         //s16 last_nearest_unsent_d = m_nearest_unsent_d;
135         s16 d_start = m_nearest_unsent_d;
136
137         //infostream<<"d_start="<<d_start<<std::endl;
138
139         u16 max_simul_sends_setting = g_settings->getU16
140                         ("max_simultaneous_block_sends_per_client");
141         u16 max_simul_sends_usually = max_simul_sends_setting;
142
143         /*
144                 Check the time from last addNode/removeNode.
145
146                 Decrease send rate if player is building stuff.
147         */
148         m_time_from_building += dtime;
149         if(m_time_from_building < g_settings->getFloat(
150                                 "full_block_send_enable_min_time_from_building"))
151         {
152                 max_simul_sends_usually
153                         = LIMITED_MAX_SIMULTANEOUS_BLOCK_SENDS;
154         }
155
156         /*
157                 Number of blocks sending + number of blocks selected for sending
158         */
159         u32 num_blocks_selected = m_blocks_sending.size();
160
161         /*
162                 next time d will be continued from the d from which the nearest
163                 unsent block was found this time.
164
165                 This is because not necessarily any of the blocks found this
166                 time are actually sent.
167         */
168         s32 new_nearest_unsent_d = -1;
169
170         const s16 full_d_max = g_settings->getS16("max_block_send_distance");
171         s16 d_max = full_d_max;
172         s16 d_max_gen = g_settings->getS16("max_block_generate_distance");
173
174         // Don't loop very much at a time
175         s16 max_d_increment_at_time = 2;
176         if(d_max > d_start + max_d_increment_at_time)
177                 d_max = d_start + max_d_increment_at_time;
178
179         s32 nearest_emerged_d = -1;
180         s32 nearest_emergefull_d = -1;
181         s32 nearest_sent_d = -1;
182         //bool queue_is_full = false;
183
184         s16 d;
185         for(d = d_start; d <= d_max; d++) {
186                 /*
187                         Get the border/face dot coordinates of a "d-radiused"
188                         box
189                 */
190                 std::vector<v3s16> list = FacePositionCache::getFacePositions(d);
191
192                 std::vector<v3s16>::iterator li;
193                 for(li = list.begin(); li != list.end(); ++li) {
194                         v3s16 p = *li + center;
195
196                         /*
197                                 Send throttling
198                                 - Don't allow too many simultaneous transfers
199                                 - EXCEPT when the blocks are very close
200
201                                 Also, don't send blocks that are already flying.
202                         */
203
204                         // Start with the usual maximum
205                         u16 max_simul_dynamic = max_simul_sends_usually;
206
207                         // If block is very close, allow full maximum
208                         if(d <= BLOCK_SEND_DISABLE_LIMITS_MAX_D)
209                                 max_simul_dynamic = max_simul_sends_setting;
210
211                         // Don't select too many blocks for sending
212                         if(num_blocks_selected >= max_simul_dynamic)
213                         {
214                                 //queue_is_full = true;
215                                 goto queue_full_break;
216                         }
217
218                         // Don't send blocks that are currently being transferred
219                         if(m_blocks_sending.find(p) != m_blocks_sending.end())
220                                 continue;
221
222                         /*
223                                 Do not go over-limit
224                         */
225                         if(p.X < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
226                         || p.X > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
227                         || p.Y < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
228                         || p.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
229                         || p.Z < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
230                         || p.Z > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE)
231                                 continue;
232
233                         // If this is true, inexistent block will be made from scratch
234                         bool generate = d <= d_max_gen;
235
236                         {
237                                 /*// Limit the generating area vertically to 2/3
238                                 if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3)
239                                         generate = false;*/
240
241                                 // Limit the send area vertically to 1/2
242                                 if(abs(p.Y - center.Y) > full_d_max / 2)
243                                         continue;
244                         }
245
246                         /*
247                                 Don't generate or send if not in sight
248                                 FIXME This only works if the client uses a small enough
249                                 FOV setting. The default of 72 degrees is fine.
250                         */
251
252                         float camera_fov = (72.0*M_PI/180) * 4./3.;
253                         if(isBlockInSight(p, camera_pos, camera_dir, camera_fov, 10000*BS) == false)
254                         {
255                                 continue;
256                         }
257
258                         /*
259                                 Don't send already sent blocks
260                         */
261                         {
262                                 if(m_blocks_sent.find(p) != m_blocks_sent.end())
263                                 {
264                                         continue;
265                                 }
266                         }
267
268                         /*
269                                 Check if map has this block
270                         */
271                         MapBlock *block = env->getMap().getBlockNoCreateNoEx(p);
272
273                         bool surely_not_found_on_disk = false;
274                         bool block_is_invalid = false;
275                         if(block != NULL)
276                         {
277                                 // Reset usage timer, this block will be of use in the future.
278                                 block->resetUsageTimer();
279
280                                 // Block is dummy if data doesn't exist.
281                                 // It means it has been not found from disk and not generated
282                                 if(block->isDummy())
283                                 {
284                                         surely_not_found_on_disk = true;
285                                 }
286
287                                 // Block is valid if lighting is up-to-date and data exists
288                                 if(block->isValid() == false)
289                                 {
290                                         block_is_invalid = true;
291                                 }
292
293                                 if(block->isGenerated() == false)
294                                         block_is_invalid = true;
295
296                                 /*
297                                         If block is not close, don't send it unless it is near
298                                         ground level.
299
300                                         Block is near ground level if night-time mesh
301                                         differs from day-time mesh.
302                                 */
303                                 if(d >= 4)
304                                 {
305                                         if(block->getDayNightDiff() == false)
306                                                 continue;
307                                 }
308                         }
309
310                         /*
311                                 If block has been marked to not exist on disk (dummy)
312                                 and generating new ones is not wanted, skip block.
313                         */
314                         if(generate == false && surely_not_found_on_disk == true)
315                         {
316                                 // get next one.
317                                 continue;
318                         }
319
320                         /*
321                                 Add inexistent block to emerge queue.
322                         */
323                         if(block == NULL || surely_not_found_on_disk || block_is_invalid)
324                         {
325                                 if (emerge->enqueueBlockEmerge(peer_id, p, generate)) {
326                                         if (nearest_emerged_d == -1)
327                                                 nearest_emerged_d = d;
328                                 } else {
329                                         if (nearest_emergefull_d == -1)
330                                                 nearest_emergefull_d = d;
331                                         goto queue_full_break;
332                                 }
333
334                                 // get next one.
335                                 continue;
336                         }
337
338                         if(nearest_sent_d == -1)
339                                 nearest_sent_d = d;
340
341                         /*
342                                 Add block to send queue
343                         */
344                         PrioritySortedBlockTransfer q((float)d, p, peer_id);
345
346                         dest.push_back(q);
347
348                         num_blocks_selected += 1;
349                 }
350         }
351 queue_full_break:
352
353         // If nothing was found for sending and nothing was queued for
354         // emerging, continue next time browsing from here
355         if(nearest_emerged_d != -1){
356                 new_nearest_unsent_d = nearest_emerged_d;
357         } else if(nearest_emergefull_d != -1){
358                 new_nearest_unsent_d = nearest_emergefull_d;
359         } else {
360                 if(d > g_settings->getS16("max_block_send_distance")){
361                         new_nearest_unsent_d = 0;
362                         m_nothing_to_send_pause_timer = 2.0;
363                 } else {
364                         if(nearest_sent_d != -1)
365                                 new_nearest_unsent_d = nearest_sent_d;
366                         else
367                                 new_nearest_unsent_d = d;
368                 }
369         }
370
371         if(new_nearest_unsent_d != -1)
372                 m_nearest_unsent_d = new_nearest_unsent_d;
373 }
374
375 void RemoteClient::GotBlock(v3s16 p)
376 {
377         if(m_blocks_sending.find(p) != m_blocks_sending.end())
378                 m_blocks_sending.erase(p);
379         else
380         {
381                 m_excess_gotblocks++;
382         }
383         m_blocks_sent.insert(p);
384 }
385
386 void RemoteClient::SentBlock(v3s16 p)
387 {
388         if(m_blocks_sending.find(p) == m_blocks_sending.end())
389                 m_blocks_sending[p] = 0.0;
390         else
391                 infostream<<"RemoteClient::SentBlock(): Sent block"
392                                 " already in m_blocks_sending"<<std::endl;
393 }
394
395 void RemoteClient::SetBlockNotSent(v3s16 p)
396 {
397         m_nearest_unsent_d = 0;
398
399         if(m_blocks_sending.find(p) != m_blocks_sending.end())
400                 m_blocks_sending.erase(p);
401         if(m_blocks_sent.find(p) != m_blocks_sent.end())
402                 m_blocks_sent.erase(p);
403 }
404
405 void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks)
406 {
407         m_nearest_unsent_d = 0;
408
409         for(std::map<v3s16, MapBlock*>::iterator
410                         i = blocks.begin();
411                         i != blocks.end(); ++i)
412         {
413                 v3s16 p = i->first;
414
415                 if(m_blocks_sending.find(p) != m_blocks_sending.end())
416                         m_blocks_sending.erase(p);
417                 if(m_blocks_sent.find(p) != m_blocks_sent.end())
418                         m_blocks_sent.erase(p);
419         }
420 }
421
422 void RemoteClient::notifyEvent(ClientStateEvent event)
423 {
424         std::ostringstream myerror;
425         switch (m_state)
426         {
427         case CS_Invalid:
428                 //intentionally do nothing
429                 break;
430         case CS_Created:
431                 switch(event)
432                 {
433                 case CSE_Init:
434                         m_state = CS_InitSent;
435                         break;
436                 case CSE_Disconnect:
437                         m_state = CS_Disconnecting;
438                         break;
439                 case CSE_SetDenied:
440                         m_state = CS_Denied;
441                         break;
442                 /* GotInit2 SetDefinitionsSent SetMediaSent */
443                 default:
444                         myerror << "Created: Invalid client state transition! " << event;
445                         throw ClientStateError(myerror.str());
446                 }
447                 break;
448         case CS_Denied:
449                 /* don't do anything if in denied state */
450                 break;
451         case CS_InitSent:
452                 switch(event)
453                 {
454                 case CSE_GotInit2:
455                         confirmSerializationVersion();
456                         m_state = CS_InitDone;
457                         break;
458                 case CSE_Disconnect:
459                         m_state = CS_Disconnecting;
460                         break;
461                 case CSE_SetDenied:
462                         m_state = CS_Denied;
463                         break;
464
465                 /* Init SetDefinitionsSent SetMediaSent */
466                 default:
467                         myerror << "InitSent: Invalid client state transition! " << event;
468                         throw ClientStateError(myerror.str());
469                 }
470                 break;
471
472         case CS_InitDone:
473                 switch(event)
474                 {
475                 case CSE_SetDefinitionsSent:
476                         m_state = CS_DefinitionsSent;
477                         break;
478                 case CSE_Disconnect:
479                         m_state = CS_Disconnecting;
480                         break;
481                 case CSE_SetDenied:
482                         m_state = CS_Denied;
483                         break;
484
485                 /* Init GotInit2 SetMediaSent */
486                 default:
487                         myerror << "InitDone: Invalid client state transition! " << event;
488                         throw ClientStateError(myerror.str());
489                 }
490                 break;
491         case CS_DefinitionsSent:
492                 switch(event)
493                 {
494                 case CSE_SetClientReady:
495                         m_state = CS_Active;
496                         break;
497                 case CSE_Disconnect:
498                         m_state = CS_Disconnecting;
499                         break;
500                 case CSE_SetDenied:
501                         m_state = CS_Denied;
502                         break;
503                 /* Init GotInit2 SetDefinitionsSent */
504                 default:
505                         myerror << "DefinitionsSent: Invalid client state transition! " << event;
506                         throw ClientStateError(myerror.str());
507                 }
508                 break;
509         case CS_Active:
510                 switch(event)
511                 {
512                 case CSE_SetDenied:
513                         m_state = CS_Denied;
514                         break;
515                 case CSE_Disconnect:
516                         m_state = CS_Disconnecting;
517                         break;
518                 /* Init GotInit2 SetDefinitionsSent SetMediaSent SetDenied */
519                 default:
520                         myerror << "Active: Invalid client state transition! " << event;
521                         throw ClientStateError(myerror.str());
522                         break;
523                 }
524                 break;
525         case CS_Disconnecting:
526                 /* we are already disconnecting */
527                 break;
528         }
529 }
530
531 u32 RemoteClient::uptime()
532 {
533         return getTime(PRECISION_SECONDS) - m_connection_time;
534 }
535
536 ClientInterface::ClientInterface(con::Connection* con)
537 :
538         m_con(con),
539         m_env(NULL),
540         m_print_info_timer(0.0)
541 {
542
543 }
544 ClientInterface::~ClientInterface()
545 {
546         /*
547                 Delete clients
548         */
549         {
550                 JMutexAutoLock clientslock(m_clients_mutex);
551
552                 for(std::map<u16, RemoteClient*>::iterator
553                         i = m_clients.begin();
554                         i != m_clients.end(); ++i)
555                 {
556
557                         // Delete client
558                         delete i->second;
559                 }
560         }
561 }
562
563 std::list<u16> ClientInterface::getClientIDs(ClientState min_state)
564 {
565         std::list<u16> reply;
566         JMutexAutoLock clientslock(m_clients_mutex);
567
568         for(std::map<u16, RemoteClient*>::iterator
569                 i = m_clients.begin();
570                 i != m_clients.end(); ++i)
571         {
572                 if (i->second->getState() >= min_state)
573                         reply.push_back(i->second->peer_id);
574         }
575
576         return reply;
577 }
578
579 std::vector<std::string> ClientInterface::getPlayerNames()
580 {
581         return m_clients_names;
582 }
583
584
585 void ClientInterface::step(float dtime)
586 {
587         m_print_info_timer += dtime;
588         if(m_print_info_timer >= 30.0)
589         {
590                 m_print_info_timer = 0.0;
591                 UpdatePlayerList();
592         }
593 }
594
595 void ClientInterface::UpdatePlayerList()
596 {
597         if (m_env != NULL)
598                 {
599                 std::list<u16> clients = getClientIDs();
600                 m_clients_names.clear();
601
602
603                 if(!clients.empty())
604                         infostream<<"Players:"<<std::endl;
605                 for(std::list<u16>::iterator
606                         i = clients.begin();
607                         i != clients.end(); ++i)
608                 {
609                         Player *player = m_env->getPlayer(*i);
610                         if(player==NULL)
611                                 continue;
612                         infostream<<"* "<<player->getName()<<"\t";
613
614                         {
615                                 JMutexAutoLock clientslock(m_clients_mutex);
616                                 RemoteClient* client = lockedGetClientNoEx(*i);
617                                 if(client != NULL)
618                                         client->PrintInfo(infostream);
619                         }
620                         m_clients_names.push_back(player->getName());
621                 }
622         }
623 }
624
625 void ClientInterface::send(u16 peer_id, u8 channelnum,
626                 NetworkPacket* pkt, bool reliable, bool deletepkt)
627 {
628         m_con->Send(peer_id, channelnum, pkt, reliable);
629
630         if (deletepkt)
631                 delete pkt;
632 }
633
634 void ClientInterface::sendToAll(u16 channelnum,
635                 NetworkPacket* pkt, bool reliable)
636 {
637         JMutexAutoLock clientslock(m_clients_mutex);
638         for(std::map<u16, RemoteClient*>::iterator
639                 i = m_clients.begin();
640                 i != m_clients.end(); ++i) {
641                 RemoteClient *client = i->second;
642
643                 if (client->net_proto_version != 0) {
644                         m_con->Send(client->peer_id, channelnum, pkt, reliable);
645                 }
646         }
647
648         delete pkt;
649 }
650
651 RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
652 {
653         JMutexAutoLock clientslock(m_clients_mutex);
654         std::map<u16, RemoteClient*>::iterator n;
655         n = m_clients.find(peer_id);
656         // The client may not exist; clients are immediately removed if their
657         // access is denied, and this event occurs later then.
658         if(n == m_clients.end())
659                 return NULL;
660
661         if (n->second->getState() >= state_min)
662                 return n->second;
663         else
664                 return NULL;
665 }
666
667 RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
668 {
669         std::map<u16, RemoteClient*>::iterator n;
670         n = m_clients.find(peer_id);
671         // The client may not exist; clients are immediately removed if their
672         // access is denied, and this event occurs later then.
673         if(n == m_clients.end())
674                 return NULL;
675
676         if (n->second->getState() >= state_min)
677                 return n->second;
678         else
679                 return NULL;
680 }
681
682 ClientState ClientInterface::getClientState(u16 peer_id)
683 {
684         JMutexAutoLock clientslock(m_clients_mutex);
685         std::map<u16, RemoteClient*>::iterator n;
686         n = m_clients.find(peer_id);
687         // The client may not exist; clients are immediately removed if their
688         // access is denied, and this event occurs later then.
689         if(n == m_clients.end())
690                 return CS_Invalid;
691
692         return n->second->getState();
693 }
694
695 void ClientInterface::setPlayerName(u16 peer_id,std::string name)
696 {
697         JMutexAutoLock clientslock(m_clients_mutex);
698         std::map<u16, RemoteClient*>::iterator n;
699         n = m_clients.find(peer_id);
700         // The client may not exist; clients are immediately removed if their
701         // access is denied, and this event occurs later then.
702         if(n != m_clients.end())
703                 n->second->setName(name);
704 }
705
706 void ClientInterface::DeleteClient(u16 peer_id)
707 {
708         JMutexAutoLock conlock(m_clients_mutex);
709
710         // Error check
711         std::map<u16, RemoteClient*>::iterator n;
712         n = m_clients.find(peer_id);
713         // The client may not exist; clients are immediately removed if their
714         // access is denied, and this event occurs later then.
715         if(n == m_clients.end())
716                 return;
717
718         /*
719                 Mark objects to be not known by the client
720         */
721         //TODO this should be done by client destructor!!!
722         RemoteClient *client = n->second;
723         // Handle objects
724         for(std::set<u16>::iterator
725                         i = client->m_known_objects.begin();
726                         i != client->m_known_objects.end(); ++i)
727         {
728                 // Get object
729                 u16 id = *i;
730                 ServerActiveObject* obj = m_env->getActiveObject(id);
731
732                 if(obj && obj->m_known_by_count > 0)
733                         obj->m_known_by_count--;
734         }
735
736         // Delete client
737         delete m_clients[peer_id];
738         m_clients.erase(peer_id);
739 }
740
741 void ClientInterface::CreateClient(u16 peer_id)
742 {
743         JMutexAutoLock conlock(m_clients_mutex);
744
745         // Error check
746         std::map<u16, RemoteClient*>::iterator n;
747         n = m_clients.find(peer_id);
748         // The client shouldn't already exist
749         if(n != m_clients.end()) return;
750
751         // Create client
752         RemoteClient *client = new RemoteClient();
753         client->peer_id = peer_id;
754         m_clients[client->peer_id] = client;
755 }
756
757 void ClientInterface::event(u16 peer_id, ClientStateEvent event)
758 {
759         {
760                 JMutexAutoLock clientlock(m_clients_mutex);
761
762                 // Error check
763                 std::map<u16, RemoteClient*>::iterator n;
764                 n = m_clients.find(peer_id);
765
766                 // No client to deliver event
767                 if (n == m_clients.end())
768                         return;
769                 n->second->notifyEvent(event);
770         }
771
772         if ((event == CSE_SetClientReady) ||
773                 (event == CSE_Disconnect)     ||
774                 (event == CSE_SetDenied))
775         {
776                 UpdatePlayerList();
777         }
778 }
779
780 u16 ClientInterface::getProtocolVersion(u16 peer_id)
781 {
782         JMutexAutoLock conlock(m_clients_mutex);
783
784         // Error check
785         std::map<u16, RemoteClient*>::iterator n;
786         n = m_clients.find(peer_id);
787
788         // No client to get version
789         if (n == m_clients.end())
790                 return 0;
791
792         return n->second->net_proto_version;
793 }
794
795 void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full)
796 {
797         JMutexAutoLock conlock(m_clients_mutex);
798
799         // Error check
800         std::map<u16, RemoteClient*>::iterator n;
801         n = m_clients.find(peer_id);
802
803         // No client to set versions
804         if (n == m_clients.end())
805                 return;
806
807         n->second->setVersionInfo(major,minor,patch,full);
808 }