parent
2ef3684c14
commit
fc126d599e
|
@ -239,35 +239,38 @@ var commands = &CommandControl{
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *CommandControl) RunCommand(command string, args []string, sender *Client) string {
|
func (cc *CommandControl) RunCommand(command string, args []string, sender *Client) string {
|
||||||
|
// get correct command from combined commands
|
||||||
|
cmd := common.GetFullChatCommand(command)
|
||||||
|
|
||||||
// Look for user command
|
// Look for user command
|
||||||
if userCmd, ok := cc.user[command]; ok {
|
if userCmd, ok := cc.user[cmd]; ok {
|
||||||
fmt.Printf("[user] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
|
fmt.Printf("[user] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
|
||||||
return userCmd.Function(sender, args)
|
return userCmd.Function(sender, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for mod command
|
// Look for mod command
|
||||||
if modCmd, ok := cc.mod[command]; ok {
|
if modCmd, ok := cc.mod[cmd]; ok {
|
||||||
if sender.IsMod || sender.IsAdmin {
|
if sender.IsMod || sender.IsAdmin {
|
||||||
fmt.Printf("[mod] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
|
fmt.Printf("[mod] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
|
||||||
return modCmd.Function(sender, args)
|
return modCmd.Function(sender, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("[mod REJECTED] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
|
fmt.Printf("[mod REJECTED] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
|
||||||
return "You are not a mod Jebaited"
|
return "You are not a mod Jebaited"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for admin command
|
// Look for admin command
|
||||||
if adminCmd, ok := cc.admin[command]; ok {
|
if adminCmd, ok := cc.admin[cmd]; ok {
|
||||||
if sender.IsAdmin {
|
if sender.IsAdmin {
|
||||||
fmt.Printf("[admin] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
|
fmt.Printf("[admin] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
|
||||||
return adminCmd.Function(sender, args)
|
return adminCmd.Function(sender, args)
|
||||||
}
|
}
|
||||||
fmt.Printf("[admin REJECTED] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
|
fmt.Printf("[admin REJECTED] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
|
||||||
return "You are not the admin Jebaited"
|
return "You are not the admin Jebaited"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command not found
|
// Command not found
|
||||||
fmt.Printf("[cmd] %s /%s %s\n", sender.name, command, strings.Join(args, " "))
|
fmt.Printf("[cmd] %s /%s %s\n", sender.name, cmd, strings.Join(args, " "))
|
||||||
return "Invalid command."
|
return "Invalid command."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,28 @@ var (
|
||||||
CNModpass ChatCommandNames = []string{"modpass"}
|
CNModpass ChatCommandNames = []string{"modpass"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ChatCommands = []ChatCommandNames{
|
||||||
|
CNMe, CNHelp, CNCount, CNColor, CNWhoAmI, CNAuth, CNUsers,
|
||||||
|
CNSv, CNPlaying, CNUnmod, CNKick, CNBan, CNUnban,
|
||||||
|
CNMod, CNReloadPlayer, CNReloadEmotes, CNModpass,
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFullChatCommand(c string) string {
|
||||||
|
for _, names := range ChatCommands {
|
||||||
|
for _, n := range names {
|
||||||
|
if c == n {
|
||||||
|
return names.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientData struct {
|
||||||
|
Type ClientDataType
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
type ChatData struct {
|
type ChatData struct {
|
||||||
Type DataType
|
Type DataType
|
||||||
Data DataInterface
|
Data DataInterface
|
||||||
|
@ -71,22 +93,33 @@ type DataInterface interface {
|
||||||
HTML() string
|
HTML() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc DataMessage) GetType() DataType {
|
func (c ClientData) GetType() DataType {
|
||||||
|
return DTClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d DataMessage) GetType() DataType {
|
||||||
return DTChat
|
return DTChat
|
||||||
}
|
}
|
||||||
|
|
||||||
func (de DataError) GetType() DataType {
|
func (d DataError) GetType() DataType {
|
||||||
return DTError
|
return DTError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc DataCommand) GetType() DataType {
|
func (d DataCommand) GetType() DataType {
|
||||||
return DTCommand
|
return DTCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (de DataEvent) GetType() DataType {
|
func (d DataEvent) GetType() DataType {
|
||||||
return DTEvent
|
return DTEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClientDataType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
CdMessage ClientDataType = iota // a normal message from the client meant to be broadcast
|
||||||
|
CdUsers // get a list of users
|
||||||
|
)
|
||||||
|
|
||||||
type DataType int
|
type DataType int
|
||||||
|
|
||||||
// Data Types
|
// Data Types
|
||||||
|
@ -96,6 +129,7 @@ const (
|
||||||
DTError // something went wrong with the previous request
|
DTError // something went wrong with the previous request
|
||||||
DTCommand // non-chat function
|
DTCommand // non-chat function
|
||||||
DTEvent // join/leave/kick/ban events
|
DTEvent // join/leave/kick/ban events
|
||||||
|
DTClient // a message coming from the client
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseDataType(token json.Token) (DataType, error) {
|
func ParseDataType(token json.Token) (DataType, error) {
|
||||||
|
@ -139,6 +173,11 @@ const (
|
||||||
MsgError
|
MsgError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (c ClientData) HTML() string {
|
||||||
|
// Client data is for client to server communication only, so clients should not see this
|
||||||
|
return `<div style="color: red;"><span>The developer messed up. You should not be seeing this.</span></div>`
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Read this HTML from a template somewhere
|
// TODO: Read this HTML from a template somewhere
|
||||||
func (dc DataMessage) HTML() string {
|
func (dc DataMessage) HTML() string {
|
||||||
fmt.Printf("message type: %d\n", dc.Type)
|
fmt.Printf("message type: %d\n", dc.Type)
|
||||||
|
|
Loading…
Reference in New Issue