mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-25 20:22:03 -08:00
Format
This commit is contained in:
parent
729460b1ea
commit
723a426203
@ -84,4 +84,4 @@ func (b *Bsoulseek) handleDM(msg privateMessageReceive) {
|
||||
b.doDisconnect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,9 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type soulseekMessage interface {}
|
||||
type soulseekMessageResponse interface {}
|
||||
type soulseekMessage interface{}
|
||||
|
||||
type soulseekMessageResponse interface{}
|
||||
|
||||
const (
|
||||
loginMessageCode uint32 = 1
|
||||
@ -21,31 +22,30 @@ const (
|
||||
userLeftRoomMessageCode uint32 = 17
|
||||
privateMessageCode uint32 = 22
|
||||
kickedMessageCode uint32 = 41
|
||||
changePasswordMessageCode uint32 = 142
|
||||
changePasswordMessageCode uint32 = 142
|
||||
)
|
||||
|
||||
var ignoreMessageCodes = map[uint32]bool {
|
||||
7: true,
|
||||
64: true,
|
||||
69: true,
|
||||
83: true,
|
||||
84: true,
|
||||
104: true,
|
||||
113: true,
|
||||
114: true,
|
||||
115: true,
|
||||
130: true,
|
||||
133: true,
|
||||
139: true,
|
||||
140: true,
|
||||
145: true,
|
||||
146: true,
|
||||
148: true,
|
||||
160: true,
|
||||
var ignoreMessageCodes = map[uint32]bool{
|
||||
7: true,
|
||||
64: true,
|
||||
69: true,
|
||||
83: true,
|
||||
84: true,
|
||||
104: true,
|
||||
113: true,
|
||||
114: true,
|
||||
115: true,
|
||||
130: true,
|
||||
133: true,
|
||||
139: true,
|
||||
140: true,
|
||||
145: true,
|
||||
146: true,
|
||||
148: true,
|
||||
160: true,
|
||||
1003: true,
|
||||
}
|
||||
|
||||
|
||||
// 1: Login
|
||||
type loginMessage struct {
|
||||
Code uint32
|
||||
@ -67,21 +67,19 @@ type loginMessageResponseFailure struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
|
||||
// 13: Say in chatroom
|
||||
type sayChatroomMessage struct {
|
||||
Code uint32
|
||||
Room string
|
||||
Room string
|
||||
Message string
|
||||
}
|
||||
|
||||
type sayChatroomMessageReceive struct {
|
||||
Room string
|
||||
Room string
|
||||
Username string
|
||||
Message string
|
||||
Message string
|
||||
}
|
||||
|
||||
|
||||
// 14: Join room
|
||||
type joinRoomMessage struct {
|
||||
Code uint32
|
||||
@ -107,45 +105,40 @@ type joinRoomMessageResponse struct {
|
||||
Operators []string
|
||||
}
|
||||
|
||||
|
||||
// 16: User joined room
|
||||
type userJoinedRoomMessage struct {
|
||||
Room string
|
||||
Username string
|
||||
Status uint32
|
||||
AvgSpeed uint32
|
||||
UploadNum uint64
|
||||
Files uint32
|
||||
Dirs uint32
|
||||
SlotsFree uint32
|
||||
Room string
|
||||
Username string
|
||||
Status uint32
|
||||
AvgSpeed uint32
|
||||
UploadNum uint64
|
||||
Files uint32
|
||||
Dirs uint32
|
||||
SlotsFree uint32
|
||||
CountryCode string
|
||||
}
|
||||
|
||||
|
||||
// 16: User left room
|
||||
type userLeftRoomMessage struct {
|
||||
Room string
|
||||
Room string
|
||||
Username string
|
||||
}
|
||||
|
||||
|
||||
// 22: Private message (sometimes used by server to tell us errors)
|
||||
type privateMessageReceive struct {
|
||||
ID uint32
|
||||
Timestamp uint32
|
||||
Username string
|
||||
Message string
|
||||
ID uint32
|
||||
Timestamp uint32
|
||||
Username string
|
||||
Message string
|
||||
NewMessage bool
|
||||
}
|
||||
|
||||
|
||||
// 41: Kicked from server (relogged)
|
||||
type kickedMessageResponse struct {}
|
||||
|
||||
type kickedMessageResponse struct{}
|
||||
|
||||
// 142: Change password
|
||||
type changePasswordMessage struct {
|
||||
Code uint32
|
||||
Code uint32
|
||||
Password string
|
||||
}
|
||||
|
||||
@ -153,7 +146,6 @@ type changePasswordMessageResponse struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
|
||||
func packMessage(message soulseekMessage) ([]byte, error) {
|
||||
buf := &bytes.Buffer{}
|
||||
var length uint32 = 0
|
||||
@ -363,4 +355,4 @@ func makeSayChatroomMessage(room string, text string) sayChatroomMessage {
|
||||
room,
|
||||
text,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,14 @@ import (
|
||||
)
|
||||
|
||||
type Bsoulseek struct {
|
||||
conn net.Conn
|
||||
messagesToSend chan soulseekMessage
|
||||
local chan config.Message
|
||||
loginResponse chan soulseekMessageResponse
|
||||
joinRoomResponse chan joinRoomMessageResponse
|
||||
fatalErrors chan error
|
||||
disconnect chan bool
|
||||
firstConnectResponse chan error
|
||||
conn net.Conn
|
||||
messagesToSend chan soulseekMessage
|
||||
local chan config.Message
|
||||
loginResponse chan soulseekMessageResponse
|
||||
joinRoomResponse chan joinRoomMessageResponse
|
||||
fatalErrors chan error
|
||||
disconnect chan bool
|
||||
firstConnectResponse chan error
|
||||
|
||||
*bridge.Config
|
||||
}
|
||||
@ -51,7 +51,7 @@ func sliceEqual(s []string) bool {
|
||||
if len(s) <= 1 {
|
||||
return true
|
||||
}
|
||||
for _, x := range(s) {
|
||||
for _, x := range s {
|
||||
if x != s[0] {
|
||||
return false
|
||||
}
|
||||
@ -60,7 +60,7 @@ func sliceEqual(s []string) bool {
|
||||
}
|
||||
|
||||
func (b *Bsoulseek) sendMessages() {
|
||||
lastFourChatMessages := []string {"1", "2", "3", ""}
|
||||
lastFourChatMessages := []string{"1", "2", "3", ""}
|
||||
for {
|
||||
message, more := <-b.messagesToSend
|
||||
if !more {
|
||||
@ -69,7 +69,7 @@ func (b *Bsoulseek) sendMessages() {
|
||||
msg, is_say := message.(sayChatroomMessage)
|
||||
if is_say {
|
||||
// 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)
|
||||
continue
|
||||
}
|
||||
@ -174,11 +174,11 @@ func (b *Bsoulseek) loginLoop() {
|
||||
|
||||
// Now we are connected
|
||||
select {
|
||||
case err = <- b.fatalErrors:
|
||||
case err = <-b.fatalErrors:
|
||||
b.Log.Errorf("%s", err)
|
||||
// Retry connect
|
||||
continue
|
||||
case <- b.disconnect:
|
||||
case <-b.disconnect:
|
||||
// We are done
|
||||
return
|
||||
}
|
||||
@ -191,7 +191,6 @@ func (b *Bsoulseek) Connect() error {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
func (b *Bsoulseek) JoinChannel(channel config.ChannelInfo) error {
|
||||
b.messagesToSend <- makeJoinRoomMessage(channel.Name)
|
||||
select {
|
||||
@ -203,18 +202,16 @@ func (b *Bsoulseek) JoinChannel(channel config.ChannelInfo) error {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (b *Bsoulseek) Send(msg config.Message) (string, error) {
|
||||
// Only process text messages
|
||||
b.Log.Debugf("=> Received local message %v", msg)
|
||||
if msg.Event != "" && msg.Event != config.EventUserAction && msg.Event != config.EventJoinLeave {
|
||||
return "", nil
|
||||
}
|
||||
b.messagesToSend <- makeSayChatroomMessage(msg.Channel, msg.Username + msg.Text)
|
||||
b.messagesToSend <- makeSayChatroomMessage(msg.Channel, msg.Username+msg.Text)
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
||||
func (b *Bsoulseek) doDisconnect() error {
|
||||
b.disconnect <- true
|
||||
close(b.messagesToSend)
|
||||
@ -224,8 +221,7 @@ func (b *Bsoulseek) doDisconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (b *Bsoulseek) Disconnect() error {
|
||||
b.doDisconnect()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user