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