-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauto_include.ms
154 lines (126 loc) · 6.28 KB
/
auto_include.ms
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
/*
persistence layout:
chmail.
|
+- inbox.<username> (array) # storage of actual mail messages.
| |
| +- message: {<sender>, <msg>, 'mail'}
| |
| +- item: {<sender>, '<itemid[:data]>,<count>', 'item'}
| |
| +- multiline message: {<sender>, <msg>, 'multiline-mail'}
|
+- options (array) # systemwide options.
| |
| +- <name>: value
|
+- poptions.<username> (array) # for users to customise their experience
| |
| +- <name>: value
|
+- tracking.<username>.<trackid> (variable) # tracking of things like cooldown timeouts
Permission nodes:
chmail.send
chmail.send.bypasstimeout
chmail.send.item
chmail.receive.item
chmail.send.item.self
chmail.send.item.allworlds
System options:
sendtimeout
Player options
sendtimeout (overrides system option)
*/
include('dispatch.ms')
include('util.ms')
include('read.ms')
include('send.ms')
include('senditem.ms')
# Proc that will initialize multiline mail composition
proc(_init_mail_chat, @recipient,
import(@mail_messages)
import(@recipients)
# Add the user to the list of people composing mail, and add their message's recipient.
assign(@mail_messages[to_lower(player())], null)
export(@mail_messages)
assign(@recipients[to_lower(player())], @recipient)
export(@recipients)
# Are there already people composing mail?
# (check for an empty array too, just in case something derped ##wait until we make sure it actually works!##)
if(not(is_null(@mail_messages)) || length(@mail_messages) == 0,
# If there aren't, go ahead and bind everything.
# Event for accumulating chat messages to be sent back to the user upon completion of their mail message
bind(player_chat, 'mail-hold-back-chat', null, @event,
import(@mail_messages)
# Is the user composing mail?
if(array_index_exists(@mail_messages, to_lower(player())),
# If they are, die. They're not chatting anything :P
cancel()
return()
, # else
# If they aren't, first make sure that their chat doesn't go to the people composing mail.
foreach(array_keys(@mail_messages), @player,
foreach(@event[recipients], @i,
if(array_contains_ic(@event[recipients][@i], @player),
array_remove(@event[recipients], @i)
)
)
)
# Then, add their chat to each mail-composing player's hold queue.
import(@held_back_chat)
# The pinfo(4) here is to make sure the player's display name is used (instead of just player()) as it appears in the chat.
assign(@message, concat('<', pinfo(4), '> ', @event[message]))
foreach(array_keys(@mail_messages), @player,
assign(@held_back_chat[@player], @message)
)
export(@held_back_chat)
)
)
# Event for composing multi-line mail messages
bind(player_chat, 'mail-compose', null, @event,
import(@mail_messages)
import(@recipients)
# Is the player actually composing mail?
if(not(array_contains_ic(array_keys(@mail_messages), to_lower(player()))),
# If they aren't, die. Let's get everything to the right place, people!
cancel()
return()
, # else
# If they are, see what they typed.
# But first, make sure their chat message doesn't actually end up being a chat message. :P
assign(@event[recipients], null)
switch(@event[message],
'-send',
# If they typed -send, send off the message!
_send_mail(player(), @recipients[to_lower(player())], @mail_messages[to_lower(player())], 'multiline-mail')
# And let them know it was sent, of course.
msg(color(green), 'Mail successfully sent to ', color(yellow), @recipients[to_lower(player())], color(green), '!')
# Resolve their removal from the mail-composing list.
_resolve_mail_list_removal()
,
'-cancel',
# If they typed -cancel, toss out the message and remove them from the mail-composing and recipient lists
# without actually sending or saving anything.
msg(color(c), 'Message canceled.')
# Resolve their removal from the mail-composing list.
_resolve_mail_list_removal()
,
# default
# If they didn't type a "command", start/continue writing to their mail message.
# Firstly, though, is there actually a mail message there yet?
if(not(@mail_messages[to_lower(player())]),
# If not, simply set the mail message to the chat message.
assign(@mail_messages[to_lower(player())], @event[message])
, # else
# Otherwise, append to the mail message instead.
assign(@mail_messages[to_lower(player())], concat(@mail_messages[to_lower(player())], '\n', @event[message]))
)
export(@mail_messages)
# Then, we give them back what they typed in the chat, for readability and mental organization.
msg(color(7), @event[message])
#
)
)
)
)
)