aboutsummaryrefslogtreecommitdiff
path: root/msg.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 08:52:23 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 08:52:23 +0800
commitd201e74fff4e6d82d639d858826bdb4190936c07 (patch)
tree7e5de8e206bf913fc0bbef5eba81b06fa9c1e06c /msg.go
parentAdd basic command handling (diff)
downloadmeseircd-d201e74fff4e6d82d639d858826bdb4190936c07.tar.gz
meseircd-d201e74fff4e6d82d639d858826bdb4190936c07.tar.zst
meseircd-d201e74fff4e6d82d639d858826bdb4190936c07.zip
Server and self awareness
Diffstat (limited to 'msg.go')
-rw-r--r--msg.go53
1 files changed, 41 insertions, 12 deletions
diff --git a/msg.go b/msg.go
index 1743116..87ed1ab 100644
--- a/msg.go
+++ b/msg.go
@@ -5,10 +5,10 @@ import (
)
type RMsg struct {
- RawSource string
- Command string
- Tags map[string]string
- Params []string
+ RawSource string
+ Command string
+ Tags map[string]string
+ Params []string
}
type Sourceable interface {
@@ -17,36 +17,65 @@ type Sourceable interface {
}
type SMsg struct {
- Source *Sourceable
- Command string
- Tags map[string]string
- Params []string
+ Source Sourceable
+ Command string
+ Tags map[string]string
+ Params []string
}
func (msg *SMsg) ClientSerialize() (final string) {
if msg.Tags != nil && len(msg.Tags) != 0 {
final = "@"
- for k, v := range msg.Tags{
+ for k, v := range msg.Tags {
// TODO: Tag values must be escaped
final += k + "=" + v + ";"
}
final += " "
}
if msg.Source != nil {
- final += ":" + (*msg.Source).ClientSource() + " "
+ final += ":" + msg.Source.ClientSource() + " "
}
final += msg.Command + " "
if len(msg.Params) > 0 {
- for i := 0; i < len(msg.Params) - 1; i++ {
+ for i := 0; i < len(msg.Params)-1; i++ {
final += msg.Params[i] + " "
}
- final += ":" + msg.Params[len(msg.Params) - 1]
+ final += ":" + msg.Params[len(msg.Params)-1]
}
final += "\n"
return
}
+func (msg *SMsg) ServerSerialize() (final string) {
+ if msg.Tags != nil && len(msg.Tags) != 0 {
+ final = "@"
+ for k, v := range msg.Tags {
+ // TODO: Tag values must be escaped
+ final += k + "=" + v + ";"
+ }
+ final += " "
+ }
+ if msg.Source != nil {
+ final += ":" + msg.Source.ServerSource() + " "
+ }
+ final += msg.Command + " "
+
+ if len(msg.Params) > 0 {
+ for i := 0; i < len(msg.Params)-1; i++ {
+ final += msg.Params[i] + " "
+ }
+ final += ":" + msg.Params[len(msg.Params)-1]
+ }
+ final += "\n"
+ return
+}
+
+func MakeMsg(source Sourceable, command string, params ...string) (msg SMsg) {
+ // TODO: Add tags
+ return SMsg{Source: source, Command: command, Params: params}
+}
+
// Partially adapted from https://github.com/ergochat/irc-go.git
func parseIRCMsg(line string) (msg RMsg, err error) {
msg = RMsg{}