fix(lint): automated linting, with simple formatter.

This commit is contained in:
Houmgaor
2025-10-19 22:43:05 +02:00
parent f79e05c0c9
commit 1398383a8d
12 changed files with 84 additions and 104 deletions

View File

@@ -12,11 +12,11 @@ type ChatType uint8
// Chat types
const (
ChatTypeWorld ChatType = 0
ChatTypeStage = 1
ChatTypeGuild = 2
ChatTypeAlliance = 3
ChatTypeParty = 4
ChatTypeWhisper = 5
ChatTypeStage ChatType = 1
ChatTypeGuild ChatType = 2
ChatTypeAlliance ChatType = 3
ChatTypeParty ChatType = 4
ChatTypeWhisper ChatType = 5
)
// MsgBinChat is a binpacket for chat messages.

View File

@@ -179,9 +179,7 @@ func handleMsgSysLogout(s *Session, p mhfpacket.MHFPacket) {
func logoutPlayer(s *Session) {
s.server.Lock()
if _, exists := s.server.sessions[s.rawConn]; exists {
delete(s.server.sessions, s.rawConn)
}
delete(s.server.sessions, s.rawConn)
s.rawConn.Close()
delete(s.server.objectIDs, s)
s.server.Unlock()
@@ -244,9 +242,7 @@ func logoutPlayer(s *Session) {
s.server.Lock()
for _, stage := range s.server.stages {
if _, exists := stage.reservedClientSlots[s.charID]; exists {
delete(stage.reservedClientSlots, s.charID)
}
delete(stage.reservedClientSlots, s.charID)
}
s.server.Unlock()
@@ -366,10 +362,7 @@ func handleMsgSysRightsReload(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfTransitMessage(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfTransitMessage)
local := false
if strings.Split(s.rawConn.RemoteAddr().String(), ":")[0] == "127.0.0.1" {
local = true
}
local := strings.Split(s.rawConn.RemoteAddr().String(), ":")[0] == "127.0.0.1"
var maxResults, port, count uint16
var cid uint32

View File

@@ -243,9 +243,10 @@ func parseChatCommand(s *Session, command string) {
sendServerChatMessage(s, s.server.i18n.commands.kqf.version)
} else {
if len(args) > 1 {
if args[1] == "get" {
switch args[1] {
case "get":
sendServerChatMessage(s, fmt.Sprintf(s.server.i18n.commands.kqf.get, s.kqf))
} else if args[1] == "set" {
case "set":
if len(args) > 2 && len(args[2]) == 16 {
hexd, _ := hex.DecodeString(args[2])
s.kqf = hexd
@@ -281,13 +282,13 @@ func parseChatCommand(s *Session, command string) {
if len(args) > 1 {
for _, course := range mhfcourse.Courses() {
for _, alias := range course.Aliases() {
if strings.ToLower(args[1]) == strings.ToLower(alias) {
if strings.EqualFold(args[1], alias) {
if slices.Contains(s.server.erupeConfig.Courses, _config.Course{Name: course.Aliases()[0], Enabled: true}) {
var delta, rightsInt uint32
if mhfcourse.CourseExists(course.ID, s.courses) {
ei := slices.IndexFunc(s.courses, func(c mhfcourse.Course) bool {
for _, alias := range c.Aliases() {
if strings.ToLower(args[1]) == strings.ToLower(alias) {
if strings.EqualFold(args[1], alias) {
return true
}
}
@@ -409,7 +410,7 @@ func parseChatCommand(s *Session, command string) {
}
case commands["Playtime"].Prefix:
if commands["Playtime"].Enabled || s.isOp() {
playtime := s.playtime + uint32(time.Now().Sub(s.playtimeTime).Seconds())
playtime := s.playtime + uint32(time.Since(s.playtimeTime).Seconds())
sendServerChatMessage(s, fmt.Sprintf(s.server.i18n.commands.playtime, playtime/60/60, playtime/60%60, playtime%60))
} else {
sendDisabledCommandMessage(s, commands["Playtime"])

View File

@@ -58,7 +58,7 @@ func handleMsgMhfSavedata(s *Session, p mhfpacket.MHFPacket) {
s.playtimeTime = time.Now()
// Bypass name-checker if new
if characterSaveData.IsNewCharacter == true {
if characterSaveData.IsNewCharacter {
s.Name = characterSaveData.Name
}

View File

@@ -190,7 +190,7 @@ func (guild *Guild) Save(s *Session) error {
UPDATE guilds SET main_motto=$2, sub_motto=$3, comment=$4, pugi_name_1=$5, pugi_name_2=$6, pugi_name_3=$7,
pugi_outfit_1=$8, pugi_outfit_2=$9, pugi_outfit_3=$10, pugi_outfits=$11, icon=$12, leader_id=$13 WHERE id=$1
`, guild.ID, guild.MainMotto, guild.SubMotto, guild.Comment, guild.PugiName1, guild.PugiName2, guild.PugiName3,
guild.PugiOutfit1, guild.PugiOutfit2, guild.PugiOutfit3, guild.PugiOutfits, guild.Icon, guild.GuildLeader.LeaderCharID)
guild.PugiOutfit1, guild.PugiOutfit2, guild.PugiOutfit3, guild.PugiOutfits, guild.Icon, guild.LeaderCharID)
if err != nil {
s.logger.Error("failed to update guild data", zap.Error(err), zap.Uint32("guildID", guild.ID))

View File

@@ -50,20 +50,20 @@ func TestGuildCreation(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
guild := &Guild{
ID: 1,
Name: tt.guildName,
MainMotto: tt.motto,
SubMotto: 1,
CreatedAt: time.Now(),
MemberCount: 1,
RankRP: 0,
EventRP: 0,
RoomRP: 0,
Comment: "Test guild",
Recruiting: true,
ID: 1,
Name: tt.guildName,
MainMotto: tt.motto,
SubMotto: 1,
CreatedAt: time.Now(),
MemberCount: 1,
RankRP: 0,
EventRP: 0,
RoomRP: 0,
Comment: "Test guild",
Recruiting: true,
FestivalColor: FestivalColorNone,
Souls: 0,
AllianceID: 0,
Souls: 0,
AllianceID: 0,
GuildLeader: GuildLeader{
LeaderCharID: tt.leaderId,
LeaderName: "TestLeader",
@@ -74,8 +74,8 @@ func TestGuildCreation(t *testing.T) {
t.Errorf("guild name validity check failed for '%s'", guild.Name)
}
if guild.GuildLeader.LeaderCharID != tt.leaderId {
t.Errorf("guild leader ID mismatch: got %d, want %d", guild.GuildLeader.LeaderCharID, tt.leaderId)
if guild.LeaderCharID != tt.leaderId {
t.Errorf("guild leader ID mismatch: got %d, want %d", guild.LeaderCharID, tt.leaderId)
}
})
}
@@ -290,12 +290,12 @@ func TestGuildLeaderAssignment(t *testing.T) {
},
}
if guild.GuildLeader.LeaderCharID != tt.leaderId {
t.Errorf("leader ID mismatch: got %d, want %d", guild.GuildLeader.LeaderCharID, tt.leaderId)
if guild.LeaderCharID != tt.leaderId {
t.Errorf("leader ID mismatch: got %d, want %d", guild.LeaderCharID, tt.leaderId)
}
if guild.GuildLeader.LeaderName != tt.leaderName {
t.Errorf("leader name mismatch: got %s, want %s", guild.GuildLeader.LeaderName, tt.leaderName)
if guild.LeaderName != tt.leaderName {
t.Errorf("leader name mismatch: got %s, want %s", guild.LeaderName, tt.leaderName)
}
})
}
@@ -345,7 +345,7 @@ func TestGuildApplicationTypes(t *testing.T) {
// TestGuildApplicationCreation tests guild application creation
func TestGuildApplicationCreation(t *testing.T) {
tests := []struct {
name string
name string
guildId uint32
charId uint32
valid bool
@@ -481,11 +481,11 @@ func TestGuildMemberCount(t *testing.T) {
// TestGuildRP tests guild RP (rank points and event points)
func TestGuildRP(t *testing.T) {
tests := []struct {
name string
rankRP uint32
eventRP uint32
roomRP uint16
valid bool
name string
rankRP uint32
eventRP uint32
roomRP uint16
valid bool
}{
{
name: "minimal_rp",
@@ -580,10 +580,10 @@ func TestGuildCommentHandling(t *testing.T) {
// TestGuildMottoSelection tests guild motto (main and sub mottos)
func TestGuildMottoSelection(t *testing.T) {
tests := []struct {
name string
mainMot uint8
subMot uint8
valid bool
name string
mainMot uint8
subMot uint8
valid bool
}{
{
name: "motto_pair_0_0",
@@ -691,38 +691,38 @@ func TestGuildSoulTracking(t *testing.T) {
// TestGuildPugiData tests guild pug i (treasure chest) names and outfits
func TestGuildPugiData(t *testing.T) {
tests := []struct {
name string
pugiNames [3]string
name string
pugiNames [3]string
pugiOutfits [3]uint8
valid bool
valid bool
}{
{
name: "empty_pugi_data",
pugiNames: [3]string{"", "", ""},
name: "empty_pugi_data",
pugiNames: [3]string{"", "", ""},
pugiOutfits: [3]uint8{0, 0, 0},
valid: true,
valid: true,
},
{
name: "all_pugi_filled",
pugiNames: [3]string{"Chest1", "Chest2", "Chest3"},
name: "all_pugi_filled",
pugiNames: [3]string{"Chest1", "Chest2", "Chest3"},
pugiOutfits: [3]uint8{1, 2, 3},
valid: true,
valid: true,
},
{
name: "mixed_pugi_data",
pugiNames: [3]string{"MainChest", "", "AltChest"},
name: "mixed_pugi_data",
pugiNames: [3]string{"MainChest", "", "AltChest"},
pugiOutfits: [3]uint8{5, 0, 10},
valid: true,
valid: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
guild := &Guild{
ID: 1,
PugiName1: tt.pugiNames[0],
PugiName2: tt.pugiNames[1],
PugiName3: tt.pugiNames[2],
ID: 1,
PugiName1: tt.pugiNames[0],
PugiName2: tt.pugiNames[1],
PugiName3: tt.pugiNames[2],
PugiOutfit1: tt.pugiOutfits[0],
PugiOutfit2: tt.pugiOutfits[1],
PugiOutfit3: tt.pugiOutfits[2],
@@ -766,7 +766,7 @@ func TestGuildRoomExpiry(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
guild := &Guild{
ID: 1,
ID: 1,
RoomExpiry: tt.expiry,
}
@@ -777,7 +777,7 @@ func TestGuildRoomExpiry(t *testing.T) {
}
}
if guild.RoomExpiry == tt.expiry {
if guild.RoomExpiry.Equal(tt.expiry) {
// Success - times match
} else if !tt.hasExpiry && guild.RoomExpiry.IsZero() {
// Success - both zero
@@ -789,23 +789,23 @@ func TestGuildRoomExpiry(t *testing.T) {
// TestGuildAllianceRelationship tests guild alliance ID tracking
func TestGuildAllianceRelationship(t *testing.T) {
tests := []struct {
name string
allianceId uint32
name string
allianceId uint32
hasAlliance bool
}{
{
name: "no_alliance",
allianceId: 0,
name: "no_alliance",
allianceId: 0,
hasAlliance: false,
},
{
name: "single_alliance",
allianceId: 1,
name: "single_alliance",
allianceId: 1,
hasAlliance: true,
},
{
name: "large_alliance_id",
allianceId: 999999,
name: "large_alliance_id",
allianceId: 999999,
hasAlliance: true,
},
}
@@ -813,7 +813,7 @@ func TestGuildAllianceRelationship(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
guild := &Guild{
ID: 1,
ID: 1,
AllianceID: tt.allianceId,
}

View File

@@ -258,7 +258,7 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
data := loadQuestFile(s, questId)
if data == nil {
return nil, fmt.Errorf(fmt.Sprintf("failed to load quest file (%d)", questId))
return nil, fmt.Errorf("failed to load quest file (%d)", questId)
}
bf := byteframe.NewByteFrame()

View File

@@ -12,9 +12,7 @@ import (
func removeSessionFromSemaphore(s *Session) {
s.server.semaphoreLock.Lock()
for _, semaphore := range s.server.semaphore {
if _, exists := semaphore.clients[s]; exists {
delete(semaphore.clients, s)
}
delete(semaphore.clients, s)
}
s.server.semaphoreLock.Unlock()
}

View File

@@ -392,10 +392,8 @@ func getRandomEntries(entries []GachaEntry, rolls int, isBox bool) ([]GachaEntry
for i := range entries {
totalWeight += entries[i].Weight
}
for {
if rolls == len(chosen) {
break
}
for rolls != len(chosen) {
if !isBox {
result := rand.Float64() * totalWeight
for _, entry := range entries {

View File

@@ -195,13 +195,9 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
return
}
if _, exists := s.stage.reservedClientSlots[s.charID]; exists {
delete(s.stage.reservedClientSlots, s.charID)
}
delete(s.stage.reservedClientSlots, s.charID)
if _, exists := s.server.stages[backStage].reservedClientSlots[s.charID]; exists {
delete(s.server.stages[backStage].reservedClientSlots, s.charID)
}
delete(s.server.stages[backStage].reservedClientSlots, s.charID)
doStageTransfer(s, pkt.AckHandle, backStage)
}
@@ -293,9 +289,7 @@ func handleMsgSysUnreserveStage(s *Session, p mhfpacket.MHFPacket) {
s.Unlock()
if stage != nil {
stage.Lock()
if _, exists := stage.reservedClientSlots[s.charID]; exists {
delete(stage.reservedClientSlots, s.charID)
}
delete(stage.reservedClientSlots, s.charID)
stage.Unlock()
}
}

View File

@@ -281,12 +281,10 @@ func (s *Server) manageSessions() {
}
func (s *Server) invalidateSessions() {
for {
if s.isShuttingDown {
break
}
for !s.isShuttingDown {
for _, sess := range s.sessions {
if time.Now().Sub(sess.lastPacket) > time.Second*time.Duration(30) {
if time.Since(sess.lastPacket) > time.Second*time.Duration(30) {
s.logger.Info("session timeout", zap.String("Name", sess.Name))
logoutPlayer(sess)
}

View File

@@ -115,10 +115,8 @@ func (s *Server) handleEntranceServerConnection(conn net.Conn) {
fmt.Printf("[Client] -> [Server]\nData [%d bytes]:\n%s\n", len(pkt), hex.Dump(pkt))
}
local := false
if strings.Split(conn.RemoteAddr().String(), ":")[0] == "127.0.0.1" {
local = true
}
local := strings.Split(conn.RemoteAddr().String(), ":")[0] == "127.0.0.1"
data := makeSv2Resp(s.erupeConfig, s, local)
if len(pkt) > 5 {
data = append(data, makeUsrResp(pkt, s)...)