Files
Erupe/server/channelserver/sys_semaphore.go
Houmgaor 2a0e3e2c84 fix: re-enable CI lint job and fix ~65 lint errors (partial)
Re-enable the golangci-lint job in CI (disabled Oct 2025), update to
Go 1.25 and golangci-lint-action v7. Fix errcheck, gosimple S1009,
staticcheck SA4031 and SA2001 errors across 54 files. Remaining ~39
lint errors will be addressed in follow-up commits.
2026-02-17 17:59:00 +01:00

60 lines
1.3 KiB
Go

package channelserver
import (
"erupe-ce/common/byteframe"
"erupe-ce/network/mhfpacket"
"sync"
)
// Semaphore holds Semaphore-specific information
type Semaphore struct {
sync.RWMutex
// Semaphore ID string
name string
id uint32
// Map of session -> charID.
// These are clients that are registered to the Semaphore
clients map[*Session]uint32
// Max Players for Semaphore
maxPlayers uint16
host *Session
}
// NewSemaphore creates a new Semaphore with intialized values
func NewSemaphore(s *Session, ID string, MaxPlayers uint16) *Semaphore {
sema := &Semaphore{
name: ID,
id: s.GetSemaphoreID(),
clients: make(map[*Session]uint32),
maxPlayers: MaxPlayers,
host: s,
}
return sema
}
// BroadcastMHF queues a MHFPacket to be sent to all sessions in the Semaphore
func (s *Semaphore) BroadcastMHF(pkt mhfpacket.MHFPacket, ignoredSession *Session) {
// Broadcast the data.
for session := range s.clients {
if session == ignoredSession {
continue
}
// Make the header
bf := byteframe.NewByteFrame()
bf.WriteUint16(uint16(pkt.Opcode()))
// Build the packet onto the byteframe.
_ = pkt.Build(bf, session.clientContext)
// Enqueue in a non-blocking way that drops the packet if the connections send buffer channel is full.
session.QueueSendNonBlocking(bf.Data())
}
}