SEGS  0.6.1-develop [3e741b81]
Super Entity Game Server
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 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include "GameCommand.h"
10 #include "MapEventTypes.h"
11 #include "GameData/Friend.h"
12 #include "BitStream.h"
13 #include "Logging.h"
14 
15 namespace SEGSEvents
16 {
17 
18 // [[ev_def:type]]
19 class FriendsListUpdate final : public GameCommandEvent
20 {
21 public:
22  // [[ev_def:field]]
24 
25  FriendsListUpdate(const FriendsList &friends_list) : GameCommandEvent(evFriendsListUpdate),
26  m_list(friends_list)
27  {
28  }
29  explicit FriendsListUpdate() : GameCommandEvent(evFriendsListUpdate) {}
30  void serializeto(BitStream &bs) const override
31  {
32  bs.StorePackedBits(1,type()-evFirstServerToClient); // 37
33 
34  qCDebug(logFriends) << "FL Update:" << m_list.m_has_friends << m_list.m_friends_count << m_list.m_friends.size();
35  bs.StorePackedBits(1,1); // v2 = force_update
36  bs.StorePackedBits(1,m_list.m_friends_count);
37 
38  for(int i=0; i<m_list.m_friends_count; ++i)
39  {
40  bs.StoreBits(1,m_list.m_has_friends); // if false, client will skip this iteration
41  bs.StorePackedBits(1,m_list.m_friends[i].m_db_id);
42 
43  // TODO: Lookup online status, implement: isFriendOnline()
44  //bool is_online = isFriendOnline(m_list.m_friends[i].fr_db_id);
45 
46  bs.StoreBits(1,m_list.m_friends[i].m_online_status);
47  bs.StoreString(m_list.m_friends[i].m_name);
48  bs.StorePackedBits(1,m_list.m_friends[i].m_class_idx);
49  bs.StorePackedBits(1,m_list.m_friends[i].m_origin_idx);
50 
51  if(!m_list.m_friends[i].m_online_status)
52  continue; // if friend is offline, the rest is skipped
53 
54  bs.StorePackedBits(1,m_list.m_friends[i].m_map_idx);
55  bs.StoreString(m_list.m_friends[i].m_mapname);
56  }
57  }
59 };
60 
61 } // end of SEGSEvents namespace
void StoreBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:114
Definition: GameCommand.h:16
int m_friends_count
Definition: Friend.h:34
FriendsListUpdate()
Definition: FriendsListUpdate.h:29
Definition: BitStream.h:34
Definition: LinkLevelEvent.h:13
void StorePackedBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:161
Definition: FriendsListUpdate.h:19
FriendsList m_list
Definition: FriendsListUpdate.h:23
void StoreString(const char *str)
Definition: BitStream.cpp:204
void serializeto(BitStream &bs) const override
Definition: FriendsListUpdate.h:30
uint32_t type() const
Definition: SEGSEvent.h:66
#define EVENT_IMPL(name)
Definition: SEGSEvent.h:77
std::vector< Friend > m_friends
Definition: Friend.h:35
Definition: Friend.h:30
bool m_has_friends
Definition: Friend.h:33
FriendsListUpdate(const FriendsList &friends_list)
Definition: FriendsListUpdate.h:25