SendMudMail is exported for use by other modules. Signature: func(userId int, fromName string, message string, gold int, itm *items.Item)
(userId int, fromName string, message string, gold int, itm *items.Item)
| 185 | // SendMudMail is exported for use by other modules. |
| 186 | // Signature: func(userId int, fromName string, message string, gold int, itm *items.Item) |
| 187 | func (m *MudmailModule) SendMudMail(userId int, fromName string, message string, gold int, itm *items.Item) { |
| 188 | msg := Message{ |
| 189 | FromName: fromName, |
| 190 | Body: message, |
| 191 | Gold: gold, |
| 192 | Item: itm, |
| 193 | DateSent: time.Now(), |
| 194 | } |
| 195 | |
| 196 | // Online: update in-memory inbox and notify. |
| 197 | if u := users.GetByUserId(userId); u != nil { |
| 198 | inbox := m.inboxes[userId] |
| 199 | inbox = append(Inbox{msg}, inbox...) |
| 200 | m.inboxes[userId] = inbox |
| 201 | m.save(userId, inbox) |
| 202 | u.Command(`inbox check`) |
| 203 | return |
| 204 | } |
| 205 | |
| 206 | // Offline: read from disk, append, write back. |
| 207 | inbox := m.load(userId) |
| 208 | inbox = append(Inbox{msg}, inbox...) |
| 209 | m.save(userId, inbox) |
| 210 | } |
| 211 | |
| 212 | // Inbox management helpers. |
| 213 |
no test coverage detected