SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FriendsListUpdate.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #pragma once
9 #include "GameCommandList.h"
10 #include "NetStructures/Friend.h"
11 #include "Logging.h"
12 
13 #include "MapEvents.h"
14 #include "MapLink.h"
15 
16 class FriendsListUpdate final : public GameCommand
17 {
18 public:
20  FriendsListUpdate(FriendsList *friends_list) : GameCommand(MapEventTypes::evFriendListUpdated),
21  m_list(friends_list)
22  {
23  }
24  void serializeto(BitStream &bs) const override {
25  bs.StorePackedBits(1,type()-MapEventTypes::evFirstServerToClient); // 37
26 
27  qCDebug(logFriends) << "FL Update:" << m_list->m_has_friends << m_list->m_friends_count << m_list->m_friends.size();
28  bs.StorePackedBits(1,1); // v2 = force_update
30 
31  for(int i=0; i<m_list->m_friends_count; ++i)
32  {
33  bs.StoreBits(1,m_list->m_has_friends); // if false, client will skip this iteration
34  bs.StorePackedBits(1,m_list->m_friends[i].m_db_id);
35 
36  // TODO: Lookup online status, implement: isFriendOnline()
37  //bool is_online = isFriendOnline(m_list->m_friends[i].fr_db_id);
38 
39  bs.StoreBits(1,m_list->m_friends[i].m_online_status);
40  bs.StoreString(m_list->m_friends[i].m_name);
41  bs.StorePackedBits(1,m_list->m_friends[i].m_class_idx);
42  bs.StorePackedBits(1,m_list->m_friends[i].m_origin_idx);
43 
44  if(!m_list->m_friends[i].m_online_status)
45  continue; // if friend is offline, the rest is skipped
46 
47  bs.StorePackedBits(1,m_list->m_friends[i].m_map_idx);
48  bs.StoreString(m_list->m_friends[i].m_mapname);
49  }
50  }
51  void serializefrom(BitStream &src);
52 };
void StoreBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:114
int m_friends_count
Definition: Friend.h:29
FriendsList * m_list
Definition: FriendsListUpdate.h:19
void serializefrom(BitStream &src)
Definition: BitStream.h:30
FriendsListUpdate(FriendsList *friends_list)
Definition: FriendsListUpdate.h:20
void StorePackedBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:161
void serializeto(BitStream &bs) const override
Definition: FriendsListUpdate.h:24
void StoreString(const char *str)
Definition: BitStream.cpp:204
Definition: FriendsListUpdate.h:16
uint32_t type() const
Definition: GameCommandList.h:21
Definition: GameCommandList.h:15
std::vector< Friend > m_friends
Definition: Friend.h:30
Definition: Friend.h:25
bool m_has_friends
Definition: Friend.h:28
Definition: MapEventTypes.h:11