-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustommessages.py
98 lines (78 loc) · 2.29 KB
/
custommessages.py
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
"""
- LICENSE: GPL-3.0
- Made by sByte
A script for helping with custom messaging (screen messages)
for BetterSpades and OpenSpades.
- How to use?
Put this script on the top of the script list in config.toml,
then the functions "connection.send_cmsg(Message, Type)" and "protocol.broadcast_cmsg(Message, Type)"
Message types:
- Notice
- Status
- Warning
- Error
- Test commands:
/csay Type Message
/cpm Player Type Message
"""
from piqueserver.commands import command, get_player
from pyspades.loaders import Loader
from pyspades.common import encode
from enum import Enum
@command("csay", admin_only=True)
def csay(p, *args):
if not args:
return "Usage: /csay MessageType Message"
p.protocol.broadcast_cmsg(' '.join(args[1:]), args[0])
@command("cpm", admin_only=True)
def cpm(p, *args):
if not args:
return "Usage: /cpm Player MessageType Message"
try:
player = get_player(p.protocol,args[0])
except:
return "Invalid player"
player.send_cmsg(' '.join(args[2:]), args[1])
class EMsgTypes(Enum):
Notice = ["N% ", 3]
Status = ["C% ", 4]
Warning = ["%% ", 5]
Error = ["!% ", 6]
class customMsg(Loader):
id = 17
text = ""
msgType = 2
def read(self, read):
pass
def write(self, writer):
writer.writeByte(self.id, True)
writer.writeByte(32, True)
writer.writeByte(self.msgType, True)
writer.writeString(encode(self.text))
bsMsg = customMsg()
client_supported = ["OpenSpades", "BetterSpades"]
def apply_script(protocol, connection, config):
class csMsgProtocol(protocol):
def broadcast_cmsg(self, msg, _type):
for player in self.players.values():
player.send_cmsg(msg, _type)
class csMsgConnection(connection):
def send_cmsg(self, msg, _type):
if _type not in EMsgTypes.__members__:
self.send_chat("(Invalid MessageType) "+msg)
return
if "client" in self.client_info:
client = self.client_info["client"]
getType = EMsgTypes[_type]
if client not in client_supported:
self.send_chat(msg)
return
elif client == "BetterSpades":
bsMsg.text = msg
bsMsg.msgType = getType.value[1]
self.send_contained(bsMsg)
return
self.send_chat(getType.value[0]+msg)
else:
self.send_chat(msg)
return csMsgProtocol, csMsgConnection