EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LSCChannel.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #include "eve-server.h"
27 #include "EVEVersion.h"
28 
29 #include "Client.h"
30 #include "ConsoleCommands.h"
31 #include "chat/LSCChannel.h"
32 #include "chat/LSCService.h"
33 
34 
36  ChannelJoinChannelCharsLine line;
37 
38  line.allianceID = m_allianceID;
39  line.charID = m_charID;
40  line.corpID = m_corpID;
41  line.role = m_role;
42  line.warFactionID = m_warFactionID;
43  line.mode = m_mode;
44 
45  // extra is a list of charID, charName, charTypeID, unknown bool, unknown PyNone
46  util_Row rs;
47  rs.header.push_back("ownerID");
48  rs.header.push_back("ownerName");
49  rs.header.push_back("typeID");
50  rs.line = new PyList();
51  rs.line->AddItemInt( m_charID );
52  rs.line->AddItemString( m_charName.c_str() );
53  rs.line->AddItemInt( 1378 ); // fix this ... wtf is this??
54  line.extra = rs.Encode();//m_extra;
55 
56  return line.Encode();
57 }
58 
60  ChannelJoinChannelModsLine line;
61 
62  line.accessor = m_accessor;
63  line.admin = m_admin;
64  line.mode = m_mode;
65  line.originalMode = m_originalMode;
66  line.reason = m_reason;
67  line.untilWhen = m_untilWhen;
68 
69  return line.Encode();
70 }
71 
72 LSCChannel::LSCChannel(LSCService* svc, int32 channelID, LSC::Type type, uint32 ownerID, const char* displayName, const char* comparisonKey, std::string motd,
73  bool memberless, const char* password, bool mailingList, uint32 cspa, bool temporary, bool languageRestriction, int32 groupMessageID, int32 channelMessageID)
74 : m_service(svc),
75  m_ownerID(ownerID),
76  m_channelID(channelID),
77  m_type(type),
78  m_motd(motd),
79  m_displayName(displayName==nullptr?"":displayName),
80  m_comparisonKey(comparisonKey==nullptr?"":comparisonKey),
81  m_memberless(memberless),
82  m_password(password==nullptr?"":password),
83  m_mailingList(mailingList),
84  m_cspa(cspa),
85  m_temporary(temporary),
86  m_languageRestriction(languageRestriction),
87  m_groupMessageID(groupMessageID),
88  m_channelMessageID(channelMessageID)
89 {
90  m_mode = LSC::Mode::chConversationalist; // default mode '3' for enabling all speakers (till i figure out how to correctly set/change later)
91  _log(LSC__CHANNELS, "Creating channel %u - \"%s\"", m_channelID, (m_displayName == "") ? ((m_comparisonKey == "") ? "null" : m_comparisonKey.c_str()) : m_displayName.c_str());
92 }
93 
95  _log(LSC__CHANNELS, "Destroying channel %u - \"%s\"", m_channelID, (m_displayName == "") ? ((m_comparisonKey == "") ? "null" : m_comparisonKey.c_str()) : m_displayName.c_str());
96 }
97 
98 void LSCChannel::GetChannelInfo(int32* channelID, uint32* ownerID, std::string& displayName, std::string& motd, std::string& comparisonKey, bool* memberless, std::string& password, bool* mailingList, uint32* cspa, uint32* temporary)
99 {
100  *channelID = m_channelID;
101  *ownerID = m_ownerID;
102  displayName = m_displayName;
103  motd = m_motd;
104  comparisonKey = m_comparisonKey;
105  *memberless = m_memberless;
106  password = m_password;
107  *mailingList = m_mailingList;
108  *cspa = m_cspa;
109  *temporary = m_temporary;
110 }
111 
114  m_chars.insert(
115  std::make_pair(
116  pClient->GetCharacterID(),
117  LSCChannelChar( this, pClient->GetCorporationID(), pClient->GetCharacterID(), pClient->GetCharName(), pClient->GetAllianceID(), pClient->GetWarFactionID(), pClient->GetAccountRole(), 0,\
119  )
120  );
121  pClient->ChannelJoined( this );
122 
123  OnLSC_JoinChannel join;
124  join.sender = _MakeSenderInfo(pClient);
125  join.member_count = (int32)m_chars.size();
126  join.channelID = EncodeID();
127 
128  MulticastTarget mct;
129  std::map<uint32, LSCChannelChar>::iterator cur;
130  cur = m_chars.begin();
131  for( ; cur != m_chars.end(); ++cur )
132  mct.characters.insert( cur->first );
133  PyTuple *answer = join.Encode();
134  sEntityList.Multicast( "OnLSC", GetTypeString(), &answer, mct );
135 
136  _log(LSC__CHANNELS, "%s Joined Channel %u - %s", pClient->GetName(), m_channelID, m_displayName.c_str());
137  return true;
138 }
139 
141 {
142  if (sConsole.IsShutdown())
143  return;
144 
145  if (m_chars.empty())
146  return;
147 
148  uint32 charID = pClient->GetCharacterID();
149  if (m_chars.find(charID) == m_chars.end())
150  return;
151 
152  m_chars.erase(charID);
153 
154  MulticastTarget mct;
155  std::map<uint32, LSCChannelChar>::iterator cur;
156  cur = m_chars.begin();
157  for(; cur != m_chars.end(); ++cur)
158  mct.characters.insert( cur->first );
159 
160  OnLSC_LeaveChannel leave;
161  leave.sender = _MakeSenderInfo(pClient);
162  leave.member_count = (int32)m_chars.size();
163  leave.channelID = EncodeID();
164 
165  PyTuple *answer = leave.Encode();
166  sEntityList.Multicast("OnLSC", GetTypeString(), &answer, mct);
167 
168  _log(LSC__CHANNELS, "%s Left Channel %u - %s", pClient->GetName(), m_channelID, m_displayName.c_str());
169 
170  pClient->ChannelLeft(this);
171 
173 }
174 
176  OnLSC_DestroyChannel dc;
177 
178  dc.channelID = EncodeID();
179  dc.member_count = 0;
180  dc.sender = _MakeSenderInfo(c);
181 
182  MulticastTarget mct;
183 
184  std::map<uint32, LSCChannelChar>::iterator cur;
185  cur = m_chars.begin();
186  for(; cur != m_chars.end(); cur++)
187  mct.characters.insert(cur->first);
188 
189  PyTuple *answer = dc.Encode();
190  sEntityList.Multicast("OnLSC", GetTypeString(), &answer, mct);
191 }
192 
193 void LSCChannel::SendMessage(Client * c, const char * message, bool self/*false*/) {
194 // to send system msgs, senderID should be 1 (system owner)
195 
196  MulticastTarget mct;
197  if (self) {
198  mct.characters.insert(c->GetCharacterID());
199  } else {
200  std::map<uint32, LSCChannelChar>::iterator itr = m_chars.begin();
201  for(; itr != m_chars.end(); ++itr)
202  mct.characters.insert( itr->first );
203  }
204 
205  OnLSC_SendMessage sm;
206  sm.sender = _MakeSenderInfo(c);
207  sm.channelID = EncodeID();
208  sm.message = message;
209  sm.member_count = m_chars.size();
210 
211  PyTuple *answer = sm.Encode();
212  sEntityList.Multicast("OnLSC", GetTypeString(), &answer, mct);
213 }
214 
216  std::string uptime;
217  sEntityList.GetUpTime(uptime);
218  std::string msg = "<br>Welcome to EVEmu Server";
219  //msg += pClient->GetCharName();
220  msg += ".<br>Server Version: ";
221  msg += EVEMU_REVISION;
222  msg += "<br>Revision Date: ";
223  msg += EVEMU_BUILD_DATE;
224  msg += "<br>Uptime: ";
225  msg += uptime;
226  msg += "<br>Current Population: ";
227  msg += std::to_string(sEntityList.GetClientCount());
228  msg += "<br><br>Character Options:";
229  msg += "<br>Module AutoStop: ";
230  msg += (pClient->AutoStop() ? "On" : "Off");
231  msg += "<br>RAM Event: On";
232  //msg += (pClient->RAMEvent() ? "On" : "Off");
233  // check account roles for this one
234  msg += "<br>ShowAll: Off";
235  //msg += (pClient->ShowAll() ? "On" : "Off");
236 
237  OnLSC_SendMessage sm;
238  sm.sender = _FakeSenderInfo();
239  sm.channelID = EncodeID();
240  sm.message = msg;
241  sm.member_count = m_chars.size();
242 
243  PyTuple *answer = sm.Encode();
244  pClient->SendNotification("OnLSC", GetTypeString(), &answer);
245 }
246 
248  return (m_chars.find(charID) != m_chars.end());
249 }
250 
252 {
253  // ********** TODO **********
254  // Figure out how to send a packet to all clients subscribed to this channel that contains all channel parameters
255  // so that their clients can update everything that has changed in this channel's access control.
256  // **************************
257 
258 }
259 
260 
261 OnLSC_SenderInfo *LSCChannel::_MakeSenderInfo(Client *c) {
262  OnLSC_SenderInfo *sender = new OnLSC_SenderInfo;
263  sender->senderID = c->GetCharacterID();
264  sender->senderName = c->GetName();
265  sender->senderType = c->GetChar()->typeID();
266  sender->corpID = c->GetCorporationID();
267  sender->role = c->GetAccountRole();
268  sender->corp_role = c->GetCorpRole();
269  return sender;
270 }
271 
272 OnLSC_SenderInfo *LSCChannel::_FakeSenderInfo() {
273  OnLSC_SenderInfo *sender = new OnLSC_SenderInfo();
274  sender->senderID = 1;
275  sender->senderName = "EVE System";
276  sender->senderType = 1;
277  sender->corpID = 1;
278  sender->role = 1;
279  sender->corp_role = 1;
280  return sender;
281 }
282 
284  switch (m_type) {
285  case LSC::Type::global:
286  case LSC::Type::corp:
287  case LSC::Type::region:
291  case LSC::Type::fleet:
292  case LSC::Type::wing:
293  case LSC::Type::squad: {
294  LSCChannelMultiDesc desc;
295  desc.type = GetTypeString();
296  desc.id = m_channelID;
297  return desc.Encode();
298  }
300  case LSC::Type::alliance:
303  case LSC::Type::normal:
304  case LSC::Type::custom: {
305  return new PyInt(m_channelID);
306  }
307  }
308  return new PyInt(m_channelID);
309 }
310 
312  ChannelInfoLine line;
313  line.channelID = m_channelID;
314  line.ownerID = m_ownerID;
315  line.displayName = m_displayName;
316  line.motd = m_motd;
317  line.comparisonKey = m_comparisonKey;
318  line.memberless = m_memberless;
319  line.password = m_password;
320  line.mailingList = m_mailingList;
321  line.cspa = m_cspa;
322  line.temporary = m_temporary;
323  line.languageRestriction = m_languageRestriction;
324  line.mode = (int8)m_mode; // determine calling char's mode for this channel
325  //HACK auto-subscribe to system channels. TODO determine if calling char is subscribed to this channel
326  line.subscribed = IsStaticChannel(m_channelID);
327  line.groupMessageID = m_groupMessageID;
328  line.channelMessageID = m_channelMessageID;
329  line.estimatedMemberCount = m_chars.size();
330  return line.Encode();
331 }
332 
334  ChannelJoinChannelInfo info;
335  info.channelID = m_channelID;
336  info.comparisonKey = m_comparisonKey;
337  info.cspa = m_cspa;
338  info.displayName = m_displayName;
339  info.mailingList = m_mailingList;
340  info.memberless = m_memberless;
341  info.motd = m_motd;
342  info.ownerID = m_ownerID;
343  info.password = m_password;
344  //HACK auto-subscribe to system channels. TODO determine if calling char is subscribed to this channel
345  info.subscribed = IsStaticChannel(m_channelID);
346  info.temporary = m_temporary;
347  info.mode = (int8)m_mode; // determine calling char's mode for this channel
348  info.languageRestriction = m_languageRestriction;
349  info.groupMessageID = m_groupMessageID;
350  info.channelMessageID = m_channelMessageID;
351  info.estimatedMemberCount = m_chars.size();
352  return info.Encode();
353 }
354 
356 {
357  ChannelJoinChannelMods info;
358  info.lines = new PyList();
359  std::map<uint32, LSCChannelMod>::iterator itr = m_mods.begin();
360  for(; itr != m_mods.end(); itr++)
361  info.lines->AddItem( itr->second.Encode() );
362  return info.Encode();
363 }
364 
366  /*
367  [PyObjectData Name: util.Rowset]
368  [PyDict 3 kvp]
369  [PyString "header"]
370  [PyList 6 items]
371  [PyString "charID"]
372  [PyString "corpID"]
373  [PyString "allianceID"]
374  [PyString "warFactionID"]
375  [PyString "role"]
376  [PyString "extra"]
377  [PyString "RowClass"]
378  [PyToken util.Row]
379  [PyString "lines"]
380  [PyList 84 items]
381  */
382  ChannelJoinChannelChars info;
383  info.lines = new PyList();
384  std::map<uint32, LSCChannelChar>::iterator itr = m_chars.begin();
385  for(; itr != m_chars.end(); itr++)
386  info.lines->AddItem( itr->second.Encode() );
387  return info.Encode();
388 }
389 
391  ChannelJoinChannelChars info;
392  info.lines = new PyList();
393  return info.Encode();
394 }
395 
397  switch(m_type) {
398  case LSC::Type::normal: return "normal";
399  case LSC::Type::custom: return "private";
400  case LSC::Type::corp: return "corpid";
401  case LSC::Type::solarsystem2: return "solarsystemid2";
402  case LSC::Type::region: return "regionid";
403  case LSC::Type::constellation: return "constellationid";
404  case LSC::Type::global: return "global";
405  case LSC::Type::alliance: return "allianceid";
406  case LSC::Type::fleet: return "fleetid";
407  case LSC::Type::squad: return "squadid";
408  case LSC::Type::wing: return "wingid";
409  case LSC::Type::warfaction: return "warfactionid";
410  case LSC::Type::character: return "charid";
411  case LSC::Type::solarsystem: return "solarsystemid";
412  case LSC::Type::incursion: return "incursion";
413  default: return "unknown";
414  }
415 }
416 
int64 GetAccountRole() const
Definition: Client.h:118
Base Python wire object.
Definition: PyRep.h:66
uint32 m_originalMode
Definition: LSCChannel.h:84
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
void ChannelLeft(LSCChannel *chan)
Definition: Client.cpp:1803
#define _log(type, fmt,...)
Definition: logsys.h:124
#define sConsole
int64 GetCorpRole() const
Definition: Client.h:129
PyRep * EncodeChannelChars()
Definition: LSCChannel.cpp:365
static OnLSC_SenderInfo * _MakeSenderInfo(Client *from)
Definition: LSCChannel.cpp:261
int64 m_untilWhen
Definition: LSCChannel.h:83
PyRep * Encode() const
Definition: LSCChannel.cpp:35
LSC::Mode m_mode
Definition: LSCChannel.h:62
std::map< uint32, LSCChannelMod > m_mods
Definition: LSCChannel.h:164
void GetChannelInfo(int32 *channelID, uint32 *ownerID, std::string &displayName, std::string &motd, std::string &comparisonKey, bool *memberless, std::string &password, bool *mailingList, uint32 *cspa, uint32 *temporary)
Definition: LSCChannel.cpp:98
uint16 m_cspa
Definition: LSCChannel.h:156
LSC::Type m_type
Definition: LSCChannel.h:146
int32 GetCharacterID() const
Definition: Client.h:113
int32 GetWarFactionID() const
Definition: Client.h:126
int32 GetCorporationID() const
Definition: Client.h:123
#define sEntityList
Definition: EntityList.h:208
bool m_temporary
Definition: LSCChannel.h:152
std::string m_displayName
Definition: LSCChannel.h:159
CharacterRef GetChar() const
Definition: Client.h:164
Python tuple.
Definition: PyRep.h:567
PyRep * EncodeStaticChannel(uint32 charID)
Definition: LSCChannel.cpp:311
std::string m_motd
Definition: LSCChannel.h:160
signed __int8 int8
Definition: eve-compat.h:45
int32 GetAllianceID() const
Definition: Client.h:125
bool m_languageRestriction
Definition: LSCChannel.h:153
OnLSC_SenderInfo * _FakeSenderInfo()
Definition: LSCChannel.cpp:272
signed __int32 int32
Definition: eve-compat.h:49
bool IsJoined(uint32 charID)
Definition: LSCChannel.cpp:247
uint32 m_allianceID
Definition: LSCChannel.h:58
void UpdateConfig()
Definition: LSCChannel.cpp:251
PyRep * EncodeDynamicChannel(uint32 charID)
Definition: LSCChannel.cpp:333
bool m_memberless
Definition: LSCChannel.h:150
uint32 m_ownerID
Definition: LSCChannel.h:157
void Evacuate(Client *c)
Definition: LSCChannel.cpp:175
LSCChannel(LSCService *svc, int32 channelID, LSC::Type type, uint32 ownerID, const char *displayName, const char *comparisonKey, std::string motd, bool memberless, const char *password, bool mailingList, uint32 cspa, bool temporary, bool languageRestriction, int32 groupMessageID, int32 channelMessageID)
Definition: LSCChannel.cpp:72
PyRep * EncodeEmptyChannelChars()
Definition: LSCChannel.cpp:390
void ChannelJoined(LSCChannel *chan)
Definition: Client.cpp:1799
Python integer.
Definition: PyRep.h:231
#define IsStaticChannel(itemID)
Definition: EVE_Defines.h:197
LSC::Mode m_mode
Definition: LSCChannel.h:147
const char * GetName() const
Definition: Client.h:94
PyRep * EncodeID()
Definition: LSCChannel.cpp:283
std::map< uint32, LSCChannelChar > m_chars
Definition: LSCChannel.h:165
Definition: Client.h:66
void LeaveChannel(Client *pClient)
Definition: LSCChannel.cpp:140
bool JoinChannel(Client *pClient)
Definition: LSCChannel.cpp:112
unsigned __int32 uint32
Definition: eve-compat.h:50
Type
Definition: EVE_LSC.h:71
std::set< uint32 > characters
Definition: EntityList.h:58
std::string GetCharName()
Definition: Client.h:165
uint32 m_accessor
Definition: LSCChannel.h:81
int32 m_groupMessageID
Definition: LSCChannel.h:154
const char * GetTypeString()
Definition: LSCChannel.cpp:396
bool m_mailingList
Definition: LSCChannel.h:151
std::string m_charName
Definition: LSCChannel.h:57
void SendServerMOTD(Client *pClient)
Definition: LSCChannel.cpp:215
static const char *const EVEMU_REVISION
Definition: EVEVersion.h:42
const int cspa
Definition: LSCService.cpp:132
std::string m_admin
Definition: LSCChannel.h:85
void SendMessage(Client *c, const char *message, bool self=false)
Definition: LSCChannel.cpp:193
static const char *const EVEMU_BUILD_DATE
Definition: EVEVersion.h:43
uint32 m_charID
Definition: LSCChannel.h:56
PyRep * Encode()
Definition: LSCChannel.cpp:59
LSC::Mode m_mode
Definition: LSCChannel.h:82
uint32 m_corpID
Definition: LSCChannel.h:55
int32 m_channelMessageID
Definition: LSCChannel.h:155
std::string m_comparisonKey
Definition: LSCChannel.h:161
uint32 m_warFactionID
Definition: LSCChannel.h:59
bool AutoStop()
Definition: Client.h:274
uint16 typeID() const
Python list.
Definition: PyRep.h:639
std::string m_password
Definition: LSCChannel.h:162
int32 m_channelID
Definition: LSCChannel.h:158
PyRep * EncodeChannelMods()
Definition: LSCChannel.cpp:355
std::string m_reason
Definition: LSCChannel.h:86