-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathGlobalChat.py
More file actions
798 lines (741 loc) · 34.6 KB
/
GlobalChat.py
File metadata and controls
798 lines (741 loc) · 34.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
import commands
import config
from config import ShipLabel
import data.clients
import data.players
import json
import packetFactory
import plugins.proxyplugins as plugins
from PSO2DataTools import check_irc_with_pso2
from PSO2DataTools import check_pso2_with_irc
from PSO2DataTools import replace_irc_with_pso2
from PSO2DataTools import replace_pso2_with_irc
from twisted.internet import protocol
from twisted.internet import reactor
from twisted.internet import task
from twisted.python import log
from twisted.words.protocols import irc
try:
import PSO2PDConnector
redisEnabled = True
except ImportError:
redisEnabled = False
ircSettings = config.YAMLConfig(
"cfg/gchat-irc.config.yml",
{
'enabled': False,
'nick': "PSO2IRCBot",
'server': '',
'port': 6667,
'svname': 'NickServ',
'svpass': '',
'channel': "",
'output': True,
'autoexec': [],
'discord': False
},
True
)
ircBot = None
ircMode = ircSettings['enabled']
ircOutput = ircSettings['output']
ircNick = ircSettings['nick']
ircServer = (ircSettings['server'], ircSettings['port'])
ircChannel = ircSettings['channel']
ircServicePass = ircSettings['svpass']
ircServiceName = ircSettings['svname']
discord = ircSettings['discord']
gchatSettings = config.YAMLConfig(
"cfg/gchat.config.yml",
{
'displayMode': 0,
'bubblePrefix': '',
'systemPrefix': '{whi}',
'prefix': ''
},
True
)
def doRedisGchat(message):
gchatMsg = json.loads(message['data'])
if gchatMsg['ship'] == "GIRC":
fb = "GIRC"
else:
fb = ("G-%02i") % gchatMsg['ship']
shipl = ShipLabel.get(fb, fb)
strgchatmsg = str(gchatMsg['text'].encode('utf-8'))
if not check_irc_with_pso2(strgchatmsg):
return
if gchatMsg['server'] == PSO2PDConnector.connector_conf['server_name']:
return
if gchatMsg['sender'] == 1:
for client in data.clients.connectedClients.values():
if client.preferences.get_preference('globalChat') and client.get_handle() is not None:
if lookup_gchatmode(client.preferences) == 0:
client.get_handle().send_crypto_packet(
packetFactory.TeamChatPacket(
gchatMsg['playerId'],
"[GIRC] %s" % gchatMsg['playerName'],
"[GIRC] %s" % gchatMsg['playerName'],
"%s%s" % (
client.preferences.get_preference('globalChatPrefix'),
replace_irc_with_pso2(strgchatmsg).decode('utf-8', 'ignore')
)
).build()
)
else:
client.get_handle().send_crypto_packet(
packetFactory.SystemMessagePacket(
"[GIRC] <%s> %s" % (
gchatMsg['playerName'],
"%s%s" % (
client.preferences.get_preference('globalChatPrefix'),
replace_irc_with_pso2(strgchatmsg).decode('utf-8', 'ignore')
)
),
0x3
).build()
)
else:
if ircMode:
global ircBot
if ircBot is not None:
ircBot.send_global_message(
gchatMsg['ship'],
str(gchatMsg['playerName'].encode('utf-8')),
strgchatmsg,
str(gchatMsg['server'])
)
for client_data in data.clients.connectedClients.values():
if client_data.preferences.get_preference('globalChat') and client_data.get_handle() is not None:
if lookup_gchatmode(client_data.preferences) == 0:
client_data.get_handle().send_crypto_packet(
packetFactory.TeamChatPacket(
gchatMsg['playerId'],
u"(%s) [%s] %s" % (
gchatMsg['server'],
shipl,
gchatMsg['playerName']
),
gchatMsg['playerName'], u"%s%s" % (
client_data.preferences.get_preference('globalChatPrefix'),
gchatMsg['text']
)
).build()
)
else:
client_data.get_handle().send_crypto_packet(
packetFactory.SystemMessagePacket(
u"(%s) [%s] <%s> %s" % (
gchatMsg['server'],
shipl,
gchatMsg['playerName'],
u"%s%s" % (
client_data.preferences.get_preference('globalChatPrefix'),
gchatMsg['text']
)
),
0x3
).build()
)
if redisEnabled:
PSO2PDConnector.thread.pubsub.subscribe(**{'plugin-message-gchat': doRedisGchat})
if ircMode:
# noinspection PyUnresolvedReferences
class GChatIRC(irc.IRCClient):
currentPid = 0
userIds = {}
nickmsgbuf = ""
nickbuf = ""
def __init__(self):
global ircNick
self.nickname = ircNick
self.ircOutput = ircOutput
def get_user_id(self, user):
if user not in self.userIds:
self.userIds[user] = self.currentPid
self.currentPid += 1
return self.userIds[user]
def connectionMade(self):
irc.IRCClient.connectionMade(self)
print("[GlobalChat] IRC Connected!")
def connectionLost(self, reason):
irc.IRCClient.connectionLost(self, reason)
print("[GlobalChat] IRC Connection lost!")
def joinChan(self):
global ircBot
try:
if self.factory.channel[:1] in ["#", "!", "+", "&"]:
self.join(self.factory.channel)
print("[GlobalChat] Joined %s" % self.factory.channel)
ircBot = self
else:
raise NameError(
"[GlobalChat] Failed to join {} channel must contain a #, !, + or & before the channel name".format(
self.factory.channel
)
)
except NameError as ne:
print(ne)
log.msg(ne)
def signedOn(self):
if discord:
self.msg("&bitlbee", "identify %s" % ircServicePass)
self.sendLine("OPER %s %s" % (self.nickname, ircServicePass))
for command in ircSettings['autoexec']:
self.sendLine(command)
print("[IRC-AUTO] >>> %s" % command)
task.deferLater(reactor, 15, self.joinChan)
print("[GlobalChat] Joining channels in 15 seconds...")
def privmsg(self, user, channel, msg):
if not check_irc_with_pso2(msg):
return
if channel == self.factory.channel:
if "title: [Ship " in msg:
self.nickbuf = user
self.nickmsgbuf = msg.replace("title: ", "", 1)
return
elif "title: " in msg and "title: [Ship " not in msg:
self.nickbuf = None
if self.nickbuf == user:
msg = msg.replace("description: ", "", 1)
if self.ircOutput is True:
if self.nickbuf == user:
print(
"[GlobalChat] [IRC] <{}> {}".format(
self.nickmsgbuf.split("] ")[1],
replace_irc_with_pso2(msg).decode('utf-8', 'ignore')
)
)
else:
print(
"[GlobalChat] [IRC] <{}> {}".format(
user.split("!")[0],
replace_irc_with_pso2(msg).decode('utf-8', 'ignore')
)
)
if redisEnabled:
if self.nickbuf == user:
PSO2PDConnector.db_conn.publish(
"plugin-message-gchat",
json.dumps(
{
'sender': 1,
'text': replace_irc_with_pso2(msg).decode('utf-8', 'ignore'),
'server': PSO2PDConnector.connector_conf['server_name'], 'playerName': self.nickmsgbuf,
'playerId': self.get_user_id(self.nickmsgbuf),
'ship': "GIRC"
}
)
)
else:
PSO2PDConnector.db_conn.publish(
"plugin-message-gchat",
json.dumps(
{
'sender': 1,
'text': replace_irc_with_pso2(msg).decode('utf-8', 'ignore'),
'server': PSO2PDConnector.connector_conf['server_name'],
'playerName': user.split("!")[0],
'playerId': self.get_user_id(user.split("!")[0]), 'ship': "GIRC"
}
)
)
for client in data.clients.connectedClients.values():
if discord and self.nickbuf == user:
nickmsg = self.nickmsgbuf.split(":")[0]
else:
nickmsg = user.split("!")[0]
pso2msg = replace_irc_with_pso2(msg).decode('utf-8', 'ignore')
if client.preferences.get_preference('globalChat') and client.get_handle() is not None:
if lookup_gchatmode(client.preferences) == 0:
client.get_handle().send_crypto_packet(
packetFactory.TeamChatPacket(
self.get_user_id(nickmsg),
u"[GIRC] %s" % nickmsg,
u"[GIRC] %s" % nickmsg,
u"%s%s" % (
client.preferences.get_preference('globalChatPrefix'),
pso2msg
)
).build()
)
else:
client.get_handle().send_crypto_packet(
packetFactory.SystemMessagePacket(
u"[GIRC] <{}> {}".format(
nickmsg,
u"{}{}".format(
client.preferences.get_preference('globalChatPrefix'),
pso2msg
)
),
0x3
).build()
)
else:
if not discord:
print("[IRC] <%s> %s" % (user.encode('ascii', 'ignore'), msg.encode('ascii', 'ignore')))
def noticed(self, user, channel, message):
print("[IRC] [NOTICE] %s %s" % (user, message))
if user.split("!")[0] == 'NickServ' and 'registered' in message:
global ircServicePass
global ircServiceName
if ircServicePass is not '':
self.msg(ircServiceName, "identify %s" % (ircServicePass))
print("[IRC] Sent identify command to %s." % (ircServiceName))
def action(self, user, channel, msg):
if not check_irc_with_pso2(msg):
return
if channel == self.factory.channel:
if self.ircOutput is True:
print("[GlobalChat] [IRC] * %s %s" % (user, replace_irc_with_pso2(msg).decode('utf-8', 'ignore')))
for client in data.clients.connectedClients.values():
if client.preferences.get_preference('globalChat') and client.get_handle() is not None:
if lookup_gchatmode(client.preferences) == 0:
client.get_handle().send_crypto_packet(
packetFactory.TeamChatPacket(
self.get_user_id(
user.split("!")[0]
),
u"[GIRC] %s" % user.split("!")[0],
u"[GIRC] %s" % user.split("!")[0],
u"* %s%s" % (
client.preferences.get_preference('globalChatPrefix'),
replace_irc_with_pso2(msg).decode('utf-8', 'ignore')
)
).build()
)
else:
client.get_handle().send_crypto_packet(
packetFactory.SystemMessagePacket(
u"[GIRC] <%s> * %s" % (
user.split("!")[0],
u"%s%s" % (
client.preferences.get_preference('globalChatPrefix'),
replace_irc_with_pso2(msg).decode('utf-8', 'ignore')
)
),
0x3
).build()
)
def send_global_message(self, ship, user, message, server=None):
if not check_pso2_with_irc(message):
return
fb = ("G-%02i") % ship
shipl = ShipLabel.get(fb, fb)
if server is None and redisEnabled:
server = PSO2PDConnector.connector_conf['server_name']
if discord:
if server is None:
self.say(self.factory.channel, "`[%s] %s`: %s" % (shipl, user, replace_pso2_with_irc(message)), 250)
else:
self.msg(self.factory.channel, "`(%s) [%s] %s`: %s" % (server, shipl, user, replace_pso2_with_irc(message)))
else:
if server is None:
self.msg(self.factory.channel, "[%s] <%s> %s" % (shipl, user, replace_pso2_with_irc(message)))
else:
self.msg(self.factory.channel, "(%s) [%s] <%s> %s" % (server, shipl, user, replace_pso2_with_irc(message)))
def send_channel_message(self, message):
self.msg(self.factory.channel, message)
class GIRCFactory(protocol.ClientFactory):
"""docstring for ClassName"""
def __init__(self, channel):
self.channel = channel
def buildProtocol(self, addr):
p = GChatIRC()
p.factory = self
return p
def clientConnectionLost(self, connector, reason):
connector.connect()
def clientConnectionFailed(self, connector, reason):
connector.connect()
def lookup_gchatmode(client_preferences):
return 1
if redisEnabled:
return 1
if client_preferences['gchatMode'] is not -1:
return client_preferences['gchatMode']
return gchatSettings['displayMode']
@plugins.on_start_hook
def create_preferences():
global ircMode
if ircMode:
global ircChannel
global ircServer
bot = GIRCFactory(ircChannel)
reactor.connectTCP(ircServer[0], ircServer[1], bot)
# noinspection PyUnresolvedReferences
@plugins.on_initial_connect_hook
def check_config(user):
global ircMode
if user.playerId in data.clients.connectedClients:
client_preferences = data.clients.connectedClients[user.playerId].preferences
if not client_preferences.has_preference("globalChat"):
client_preferences.set_preference("globalChat", True)
if not client_preferences.has_preference("globalChatPrefix"):
client_preferences.set_preference("globalChatPrefix", gchatSettings['prefix'])
if client_preferences.get_preference('globalChat'):
user.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Proxy] {0}Global chat is enabled. Use {1}g <Message> "
"to chat, {1}goff to disable it, and {1}gmode to toggle "
"team/system chat mode.".format(
"{yel}",
config.globalConfig['commandPrefix']
),
0x3
).build()
)
else:
user.send_crypto_packet(packetFactory.SystemMessagePacket(
"[Proxy] {0}Global chat is disabled. Use {1}gon to enable it,"
" {1}g <Message> to chat, and {1}gmode to toggle team/system "
"chat mode.".format(
"{yel}",
config.globalConfig['commandPrefix']
),
0x3
).build())
if not client_preferences.has_preference("gchatMode"):
client_preferences['gchatMode'] = -1
@plugins.CommandHook("gmode", "Sets your Global Chat display mode.")
class GChatModeCommand(commands.Command):
def call_from_client(self, client):
if client.playerId is not None:
client_preferences = data.clients.connectedClients[client.playerId].preferences
if client_preferences['gchatMode'] == -1:
client_preferences['gchatMode'] = 0
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {gre}Global chat will now come through team chat.",
0x3
).build()
)
elif client_preferences['gchatMode'] == 0:
client_preferences['gchatMode'] = 1
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {gre}Global chat will now come through system chat.",
0x3
).build()
)
elif client_preferences['gchatMode'] == 1:
client_preferences['gchatMode'] = -1
if gchatSettings['displayMode'] == 0:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {gre}Global chat will now come through team chat. (Default)",
0x3
).build()
)
else:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {gre}Global chat will now come through system chat. (Default)",
0x3
).build()
)
@plugins.CommandHook("gprefix", "Changes your Global Chat prefix / color.")
class GPrefixCommand(commands.Command):
def call_from_client(self, client):
if client.playerId is not None:
client_prefs = data.clients.connectedClients[client.playerId].preferences
if len(self.args.split(" ", 1)) < 2:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {red}Invalid usage. Usage: gprefix <Prefix or PSO2 Color Code>",
0x3
).build()
)
return
prefix = self.args.split(" ", 1)[1]
client_prefs['globalChatPrefix'] = prefix
client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {gre}Your prefix has been set.", 0x3).build())
@plugins.CommandHook("irc")
class IRCCommand(commands.Command):
def call_from_console(self):
global ircMode
global ircBot
if ircMode and ircBot is not None:
ircBot.sendLine(self.args.split(" ", 1)[1].encode('utf-8'))
return "[IRC] >>> %s" % self.args.split(" ", 1)[1]
@plugins.CommandHook("ident")
class IdentCommand(commands.Command):
def call_from_console(self):
global ircMode
global ircBot
global ircServiceName
global ircServicePass
if ircMode and ircBot is not None:
ircBot.msg(ircServiceName, "identify %s" % (ircServicePass))
return "[IRC] Sent identify command to %s." % (ircServiceName)
@plugins.CommandHook("gon", "Enable Global Chat.")
class EnableGChat(commands.Command):
def call_from_client(self, client):
preferences = data.clients.connectedClients[client.playerId].preferences
if not preferences['globalChat']:
preferences['globalChat'] = True
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[GlobalChat] Global chat has been enabled for you.",
0x3
).build()
)
else:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[GlobalChat] You already have global chat enabled.",
0x3
).build()
)
def call_from_console(self):
if ircMode:
global ircBot
if ircBot is not None:
ircBot.ircOutput = True
return "[GlobalChat] Global chat enabled for Console."
@plugins.CommandHook("goff", "Disable Global Chat.")
class DisableGChat(commands.Command):
def call_from_client(self, client):
preferences = data.clients.connectedClients[client.playerId].preferences
if preferences["globalChat"]:
preferences['globalChat'] = False
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[GlobalChat] Global chat has been disabled for you.",
0x3
).build()
)
else:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[GlobalChat] You already have global chat disabled.",
0x3
).build()
)
def call_from_console(self):
if ircMode:
global ircBot
if ircBot is not None:
ircBot.ircOutput = False
return "[GlobalChat] Global chat disabled for Console."
@plugins.CommandHook("gmute", "[Admin Only] Mutes a client in global chat.", True)
class MuteSomebody(commands.Command):
def call_from_client(self, client):
"""
:param client: ShipProxy.ShipProxy
"""
if len(self.args.split(" ", 1)) < 2:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {red}Invalid usage. gmute <Player Name>"
).build()
)
return
user_to_mute = self.args.split(" ", 1)[1]
if user_to_mute.isdigit() and int(user_to_mute) in data.clients.connectedClients:
data.clients.connectedClients[int(user_to_mute)].preferences['chatMuted'] = True
client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {gre}Muted %s." % user_to_mute, 0x3).build())
return
else:
for player_id, player_data in data.players.playerList.items():
if player_data[0].rstrip("\0") == user_to_mute:
if player_id in data.clients.connectedClients:
data.clients.connectedClients[player_id].preferences['chatMuted'] = True
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {}Muted {}.".format(
"{gre}",
player_data[0].rstrip("\0")
),
0x3
).build()
)
return
else:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {}{} either is not connected or is not part of the proxy.".format(
"{red}",
player_data[0].rstrip("\0")
),
0x3
).build()
)
return
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {}{} either is not connected or is not part of the proxy.".format(
"{red}",
user_to_mute
),
0x3
).build()
)
def call_from_console(self):
if len(self.args.split(" ", 1)) < 2:
return "[Command] Invalid usage. gmute <Player Name>"
user_to_mute = self.args.split(" ", 1)[1]
if user_to_mute.isdigit() and int(user_to_mute) in data.clients.connectedClients:
data.clients.connectedClients[int(user_to_mute)].preferences['chatMuted'] = True
return "Muted %s by Player #" % user_to_mute
for player_id, player_data in data.players.playerList.items():
if player_data[0].rstrip("\0") == user_to_mute:
if player_id in data.clients.connectedClients:
data.clients.connectedClients[player_id].preferences['chatMuted'] = True
return "[Command] Muted %s." % player_data[0].rstrip("\0")
else:
return "[Command] %s either is not connected or is not part of the proxy." % player_data[0].rstrip("\0")
return "[Command] %s either is not connected or is not part of the proxy." % user_to_mute
@plugins.CommandHook("gunmute", "[Admin Only] Unmutes a client in global chat.", True)
class UnmuteSomebody(commands.Command):
def call_from_client(self, client):
"""
:param client: ShipProxy.ShipProxy
"""
if len(self.args.split(" ", 1)) < 2:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {red}Invalid usage. gunmute <Player Name>"
).build()
)
return
user_to_mute = self.args.split(" ", 1)[1]
if user_to_mute.isdigit() and int(user_to_mute) in data.clients.connectedClients:
data.clients.connectedClients[int(user_to_mute)].preferences['chatMuted'] = False
client.send_crypto_packet(packetFactory.SystemMessagePacket("[Command] {gre}Unmuted %s." % user_to_mute, 0x3).build())
else:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {}{} either is not connected or is not part of the proxy.".format(
"{red}",
user_to_mute
),
0x3
).build()
)
for player_id, player_data in data.players.playerList.items():
if player_data[0].rstrip("\0") == user_to_mute:
if player_id in data.clients.connectedClients:
data.clients.connectedClients[player_id].preferences['chatMuted'] = False
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {}Unmuted {}.".format(
"{gre}",
player_data[0].rstrip("\0")
),
0x3
).build()
)
else:
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[Command] {}{} either is not connected or is not part of the proxy.".format(
"{red}",
player_data[0].rstrip("\0")
),
0x3
).build()
)
def call_from_console(self):
if len(self.args.split(" ", 1)) < 2:
return "[Command] Invalid usage. gunmute <Player Name>"
user_to_mute = self.args.split(" ", 1)[1]
if user_to_mute.isdigit() and int(user_to_mute) in data.clients.connectedClients:
data.clients.connectedClients[int(user_to_mute)].preferences['chatMuted'] = False
return "Unmuted %s by Player #" % user_to_mute
for player_id, player_data in data.players.playerList.items():
if player_data[0].rstrip("\0") == user_to_mute:
if player_id in data.clients.connectedClients:
data.clients.connectedClients[player_id].preferences['chatMuted'] = False
return "[Command] Unmuted %s." % player_data[0].rstrip("\0")
else:
return "[Command] %s either is not connected or is not part of the proxy." % player_data[0].rstrip("\0")
return "[Command] %s either is not connected or is not part of the proxy." % user_to_mute
@plugins.CommandHook("g", "Send a message in global chat.")
class GChat(commands.Command):
def call_from_client(self, client):
global ircMode
if not data.clients.connectedClients[client.playerId].preferences.get_preference('globalChat'):
client.send_crypto_packet(packetFactory.SystemMessagePacket(
"[GlobalChat] You do not have global chat enabled, and can not send a global message.", 0x3).build())
return
if (
data.clients.connectedClients[client.playerId].preferences.has_preference("chatMuted") and
data.clients.connectedClients[client.playerId].preferences['chatMuted']
):
client.send_crypto_packet(
packetFactory.SystemMessagePacket(
"[GChat] {red}You have been muted from GChat and can not talk in it. :(",
0x3
).build()
)
return
print("[GlobalChat] <%s> %s" % (data.players.playerList[client.playerId][0], self.args[3:]))
if redisEnabled:
PSO2PDConnector.db_conn.publish(
"plugin-message-gchat", json.dumps(
{
'sender': 0, 'text': self.args[3:],
'server': PSO2PDConnector.connector_conf['server_name'],
'playerName': data.players.playerList[client.playerId][0],
'playerId': client.playerId,
'ship': data.clients.connectedClients[client.playerId].ship
}
)
)
if ircMode:
global ircBot
if ircBot is not None:
ircBot.send_global_message(
data.clients.connectedClients[client.playerId].ship,
data.players.playerList[client.playerId][0].encode('utf-8'),
self.args[3:].encode('utf-8')
)
fb = ("G-%02i") % data.clients.connectedClients[client.playerId].ship
shipl = ShipLabel.get(fb, fb)
for client_data in data.clients.connectedClients.values():
if client_data.preferences.get_preference('globalChat') and client_data.get_handle() is not None:
if lookup_gchatmode(client_data.preferences) == 0:
client_data.get_handle().send_crypto_packet(
packetFactory.TeamChatPacket(
client.playerId,
u"[%s] %s" % (
shipl, data.players.playerList[client.playerId][0]
),
data.players.playerList[client.playerId][0],
u"%s%s" % (
client_data.preferences.get_preference('globalChatPrefix'),
self.args[3:]
)
).build()
)
else:
client_data.get_handle().send_crypto_packet(
packetFactory.SystemMessagePacket(
u"[{}] <{}> {}".format(
shipl, data.players.playerList[client.playerId][0],
u"{}{}".format(
client_data.preferences.get_preference('globalChatPrefix'),
self.args[3:]
)
),
0x3
).build()
)
def call_from_console(self):
global ircMode
gconsole = ("[%s]") % ShipLabel["Console"]
if ircMode:
global ircBot
if ircBot is not None:
ircBot.send_global_message(0, ShipLabel["Console"], self.args[2:].encode('utf-8'))
TCPacket = packetFactory.TeamChatPacket(0x999, gconsole, gconsole, self.args[2:]).build()
SMPacket = packetFactory.SystemMessagePacket(u"%s %s%s" % (gconsole, gchatSettings['prefix'], self.args[2:]), 0x3).build()
for client in data.clients.connectedClients.values():
if client.preferences.get_preference("globalChat") and client.get_handle() is not None:
if lookup_gchatmode(client.preferences) == 0:
client.get_handle().send_crypto_packet(TCPacket)
else:
client.get_handle().send_crypto_packet(SMPacket)
return "[GlobalChat] %s %s" % (gconsole, self.args[2:])