mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-16 17:05:03 +01:00
enable world chat
This commit is contained in:
@@ -141,7 +141,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
logger.Info("Started sign server")
|
logger.Info("Started sign server")
|
||||||
|
|
||||||
var channels []channelserver.Server
|
var channels []*channelserver.Server
|
||||||
channelQuery := ""
|
channelQuery := ""
|
||||||
si := 0
|
si := 0
|
||||||
ci := 0
|
ci := 0
|
||||||
@@ -164,7 +164,7 @@ func main() {
|
|||||||
logger.Fatal("Failed to start channel", zap.Error(err))
|
logger.Fatal("Failed to start channel", zap.Error(err))
|
||||||
} else {
|
} else {
|
||||||
channelQuery += fmt.Sprintf("INSERT INTO servers (server_id, season, current_players) VALUES (%d, %d, 0);", sid, season)
|
channelQuery += fmt.Sprintf("INSERT INTO servers (server_id, season, current_players) VALUES (%d, %d, 0);", sid, season)
|
||||||
channels = append(channels, c)
|
channels = append(channels, &c)
|
||||||
logger.Info(fmt.Sprintf("Started channel server %d on port %d", count, ce.Port))
|
logger.Info(fmt.Sprintf("Started channel server %d on port %d", count, ce.Port))
|
||||||
ci++
|
ci++
|
||||||
count++
|
count++
|
||||||
@@ -174,8 +174,13 @@ func main() {
|
|||||||
si++
|
si++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register all servers in DB
|
||||||
_ = db.MustExec(channelQuery)
|
_ = db.MustExec(channelQuery)
|
||||||
|
|
||||||
|
for _, c := range channels {
|
||||||
|
c.Channels = channels
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for exit or interrupt with ctrl+C.
|
// Wait for exit or interrupt with ctrl+C.
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
// Send to the proper recipients.
|
// Send to the proper recipients.
|
||||||
switch pkt.BroadcastType {
|
switch pkt.BroadcastType {
|
||||||
case BroadcastTypeWorld:
|
case BroadcastTypeWorld:
|
||||||
s.server.BroadcastMHF(resp, s)
|
s.server.WorldcastMHF(resp, s)
|
||||||
case BroadcastTypeStage:
|
case BroadcastTypeStage:
|
||||||
if isDiceCommand {
|
if isDiceCommand {
|
||||||
s.stage.BroadcastMHF(resp, nil) // send dice result back to caller
|
s.stage.BroadcastMHF(resp, nil) // send dice result back to caller
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
ps "erupe-ce/common/pascalstring"
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
"erupe-ce/config"
|
"erupe-ce/config"
|
||||||
"erupe-ce/network/binpacket"
|
"erupe-ce/network/binpacket"
|
||||||
@@ -51,6 +52,7 @@ type userBinaryPartID struct {
|
|||||||
// Server is a MHF channel server.
|
// Server is a MHF channel server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
Channels []*Server
|
||||||
ID uint16
|
ID uint16
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
@@ -291,6 +293,20 @@ func (s *Server) BroadcastMHF(pkt mhfpacket.MHFPacket, ignoredSession *Session)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) WorldcastMHF(pkt mhfpacket.MHFPacket, ignoredSession *Session) {
|
||||||
|
for _, c := range s.Channels {
|
||||||
|
for _, s := range c.sessions {
|
||||||
|
if s == ignoredSession {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
bf.WriteUint16(uint16(pkt.Opcode()))
|
||||||
|
pkt.Build(bf, s.clientContext)
|
||||||
|
s.QueueSendNonBlocking(bf.Data())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BroadcastChatMessage broadcasts a simple chat message to all the sessions.
|
// BroadcastChatMessage broadcasts a simple chat message to all the sessions.
|
||||||
func (s *Server) BroadcastChatMessage(message string) {
|
func (s *Server) BroadcastChatMessage(message string) {
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
@@ -317,27 +333,25 @@ func (s *Server) BroadcastRaviente(ip uint32, port uint16, stage []byte, _type u
|
|||||||
bf.WriteUint16(0) // Unk
|
bf.WriteUint16(0) // Unk
|
||||||
bf.WriteUint16(0x43) // Data len
|
bf.WriteUint16(0x43) // Data len
|
||||||
bf.WriteUint16(3) // Unk len
|
bf.WriteUint16(3) // Unk len
|
||||||
var d []byte
|
var text string
|
||||||
switch _type {
|
switch _type {
|
||||||
case 2:
|
case 2:
|
||||||
d = []byte("<Great Slaying: Berserk> is being held!")
|
text = "<Great Slaying: Berserk> is being held!"
|
||||||
case 4:
|
case 4:
|
||||||
d = []byte("<Great Slaying: Extreme> is being held!")
|
text = "<Great Slaying: Extreme> is being held!"
|
||||||
case 5:
|
case 5:
|
||||||
d = []byte("<Great Slaying: Berserk Practice> is being held!")
|
text = "<Great Slaying: Berserk Practice> is being held!"
|
||||||
default:
|
default:
|
||||||
s.logger.Error("Unk raviente type", zap.Uint8("_type", _type))
|
s.logger.Error("Unk raviente type", zap.Uint8("_type", _type))
|
||||||
}
|
}
|
||||||
bf.WriteUint16(uint16(len(d)+1))
|
ps.Uint16(bf, text, false)
|
||||||
bf.WriteNullTerminatedBytes(d)
|
|
||||||
bf.WriteBytes([]byte{0x5F, 0x53, 0x00})
|
bf.WriteBytes([]byte{0x5F, 0x53, 0x00})
|
||||||
bf.WriteUint32(ip) // IP address
|
bf.WriteUint32(ip) // IP address
|
||||||
bf.WriteUint16(port) // Port
|
bf.WriteUint16(port) // Port
|
||||||
bf.WriteUint16(0) // Unk
|
bf.WriteUint16(0) // Unk
|
||||||
bf.WriteNullTerminatedBytes(stage)
|
bf.WriteNullTerminatedBytes(stage)
|
||||||
bf.WriteBytes(make([]byte, 17))
|
bf.WriteBytes(make([]byte, 17))
|
||||||
|
s.WorldcastMHF(&mhfpacket.MsgSysCastedBinary{
|
||||||
s.BroadcastMHF(&mhfpacket.MsgSysCastedBinary{
|
|
||||||
CharID: 0x00000000,
|
CharID: 0x00000000,
|
||||||
BroadcastType: BroadcastTypeSemaphore,
|
BroadcastType: BroadcastTypeSemaphore,
|
||||||
MessageType: BinaryMessageTypeChat,
|
MessageType: BinaryMessageTypeChat,
|
||||||
@@ -353,9 +367,9 @@ func (s *Server) DiscordChannelSend(charName string, content string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) FindSessionByCharID(charID uint32) *Session {
|
func (s *Server) FindSessionByCharID(charID uint32) *Session {
|
||||||
s.stagesLock.RLock()
|
for _, c := range s.Channels {
|
||||||
defer s.stagesLock.RUnlock()
|
c.stagesLock.RLock()
|
||||||
for _, stage := range s.stages {
|
for _, stage := range c.stages {
|
||||||
stage.RLock()
|
stage.RLock()
|
||||||
for client := range stage.clients {
|
for client := range stage.clients {
|
||||||
if client.charID == charID {
|
if client.charID == charID {
|
||||||
@@ -365,7 +379,8 @@ func (s *Server) FindSessionByCharID(charID uint32) *Session {
|
|||||||
}
|
}
|
||||||
stage.RUnlock()
|
stage.RUnlock()
|
||||||
}
|
}
|
||||||
|
c.stagesLock.RUnlock()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user