mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-29 14:12:02 -08:00
Format
This commit is contained in:
parent
729460b1ea
commit
723a426203
@ -10,8 +10,9 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type soulseekMessage interface {}
|
type soulseekMessage interface{}
|
||||||
type soulseekMessageResponse interface {}
|
|
||||||
|
type soulseekMessageResponse interface{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
loginMessageCode uint32 = 1
|
loginMessageCode uint32 = 1
|
||||||
@ -24,7 +25,7 @@ const (
|
|||||||
changePasswordMessageCode uint32 = 142
|
changePasswordMessageCode uint32 = 142
|
||||||
)
|
)
|
||||||
|
|
||||||
var ignoreMessageCodes = map[uint32]bool {
|
var ignoreMessageCodes = map[uint32]bool{
|
||||||
7: true,
|
7: true,
|
||||||
64: true,
|
64: true,
|
||||||
69: true,
|
69: true,
|
||||||
@ -45,7 +46,6 @@ var ignoreMessageCodes = map[uint32]bool {
|
|||||||
1003: true,
|
1003: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 1: Login
|
// 1: Login
|
||||||
type loginMessage struct {
|
type loginMessage struct {
|
||||||
Code uint32
|
Code uint32
|
||||||
@ -67,7 +67,6 @@ type loginMessageResponseFailure struct {
|
|||||||
Reason string
|
Reason string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 13: Say in chatroom
|
// 13: Say in chatroom
|
||||||
type sayChatroomMessage struct {
|
type sayChatroomMessage struct {
|
||||||
Code uint32
|
Code uint32
|
||||||
@ -81,7 +80,6 @@ type sayChatroomMessageReceive struct {
|
|||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 14: Join room
|
// 14: Join room
|
||||||
type joinRoomMessage struct {
|
type joinRoomMessage struct {
|
||||||
Code uint32
|
Code uint32
|
||||||
@ -107,7 +105,6 @@ type joinRoomMessageResponse struct {
|
|||||||
Operators []string
|
Operators []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 16: User joined room
|
// 16: User joined room
|
||||||
type userJoinedRoomMessage struct {
|
type userJoinedRoomMessage struct {
|
||||||
Room string
|
Room string
|
||||||
@ -121,14 +118,12 @@ type userJoinedRoomMessage struct {
|
|||||||
CountryCode string
|
CountryCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 16: User left room
|
// 16: User left room
|
||||||
type userLeftRoomMessage struct {
|
type userLeftRoomMessage struct {
|
||||||
Room string
|
Room string
|
||||||
Username string
|
Username string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 22: Private message (sometimes used by server to tell us errors)
|
// 22: Private message (sometimes used by server to tell us errors)
|
||||||
type privateMessageReceive struct {
|
type privateMessageReceive struct {
|
||||||
ID uint32
|
ID uint32
|
||||||
@ -138,10 +133,8 @@ type privateMessageReceive struct {
|
|||||||
NewMessage bool
|
NewMessage bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 41: Kicked from server (relogged)
|
// 41: Kicked from server (relogged)
|
||||||
type kickedMessageResponse struct {}
|
type kickedMessageResponse struct{}
|
||||||
|
|
||||||
|
|
||||||
// 142: Change password
|
// 142: Change password
|
||||||
type changePasswordMessage struct {
|
type changePasswordMessage struct {
|
||||||
@ -153,7 +146,6 @@ type changePasswordMessageResponse struct {
|
|||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func packMessage(message soulseekMessage) ([]byte, error) {
|
func packMessage(message soulseekMessage) ([]byte, error) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
var length uint32 = 0
|
var length uint32 = 0
|
||||||
|
@ -51,7 +51,7 @@ func sliceEqual(s []string) bool {
|
|||||||
if len(s) <= 1 {
|
if len(s) <= 1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for _, x := range(s) {
|
for _, x := range s {
|
||||||
if x != s[0] {
|
if x != s[0] {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func sliceEqual(s []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsoulseek) sendMessages() {
|
func (b *Bsoulseek) sendMessages() {
|
||||||
lastFourChatMessages := []string {"1", "2", "3", ""}
|
lastFourChatMessages := []string{"1", "2", "3", ""}
|
||||||
for {
|
for {
|
||||||
message, more := <-b.messagesToSend
|
message, more := <-b.messagesToSend
|
||||||
if !more {
|
if !more {
|
||||||
@ -69,7 +69,7 @@ func (b *Bsoulseek) sendMessages() {
|
|||||||
msg, is_say := message.(sayChatroomMessage)
|
msg, is_say := message.(sayChatroomMessage)
|
||||||
if is_say {
|
if is_say {
|
||||||
// can't send 5 of the same message in a row or we get banned
|
// can't send 5 of the same message in a row or we get banned
|
||||||
if (sliceEqual(append(lastFourChatMessages, msg.Message))) {
|
if sliceEqual(append(lastFourChatMessages, msg.Message)) {
|
||||||
b.Log.Warnf("Dropping message: %s", msg.Message)
|
b.Log.Warnf("Dropping message: %s", msg.Message)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -174,11 +174,11 @@ func (b *Bsoulseek) loginLoop() {
|
|||||||
|
|
||||||
// Now we are connected
|
// Now we are connected
|
||||||
select {
|
select {
|
||||||
case err = <- b.fatalErrors:
|
case err = <-b.fatalErrors:
|
||||||
b.Log.Errorf("%s", err)
|
b.Log.Errorf("%s", err)
|
||||||
// Retry connect
|
// Retry connect
|
||||||
continue
|
continue
|
||||||
case <- b.disconnect:
|
case <-b.disconnect:
|
||||||
// We are done
|
// We are done
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -191,7 +191,6 @@ func (b *Bsoulseek) Connect() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b *Bsoulseek) JoinChannel(channel config.ChannelInfo) error {
|
func (b *Bsoulseek) JoinChannel(channel config.ChannelInfo) error {
|
||||||
b.messagesToSend <- makeJoinRoomMessage(channel.Name)
|
b.messagesToSend <- makeJoinRoomMessage(channel.Name)
|
||||||
select {
|
select {
|
||||||
@ -203,18 +202,16 @@ func (b *Bsoulseek) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b *Bsoulseek) Send(msg config.Message) (string, error) {
|
func (b *Bsoulseek) Send(msg config.Message) (string, error) {
|
||||||
// Only process text messages
|
// Only process text messages
|
||||||
b.Log.Debugf("=> Received local message %v", msg)
|
b.Log.Debugf("=> Received local message %v", msg)
|
||||||
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave {
|
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b.messagesToSend <- makeSayChatroomMessage(msg.Channel, msg.Username + msg.Text)
|
b.messagesToSend <- makeSayChatroomMessage(msg.Channel, msg.Username+msg.Text)
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b *Bsoulseek) doDisconnect() error {
|
func (b *Bsoulseek) doDisconnect() error {
|
||||||
b.disconnect <- true
|
b.disconnect <- true
|
||||||
close(b.messagesToSend)
|
close(b.messagesToSend)
|
||||||
@ -224,7 +221,6 @@ func (b *Bsoulseek) doDisconnect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b *Bsoulseek) Disconnect() error {
|
func (b *Bsoulseek) Disconnect() error {
|
||||||
b.doDisconnect()
|
b.doDisconnect()
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user