mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-01 15:46:17 -04:00
ServerFull Packet Implementation (#889)
* Implement ServerFullPacket including server side handling and a place holder client side. * Making suggested edits to move to an empty packet Co-authored-by: Stephen Horan <steve.horan@theatsgroup.com>
This commit is contained in:
parent
4dd69e7709
commit
aa680d030f
@ -156,6 +156,9 @@ func (g *GameClient) OnPacketReceived(packet d2netpacket.NetPacket) error {
|
||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/802
|
||||
log.Print("Server has been closed")
|
||||
os.Exit(0)
|
||||
case d2netpackettype.ServerFull:
|
||||
log.Println("Server is full")
|
||||
os.Exit(0)
|
||||
default:
|
||||
log.Fatalf("Invalid packet type: %d", packet.PacketType)
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ const (
|
||||
CastSkill // Sent by client or server, indicates entity casting skill
|
||||
SpawnItem // Sent by server
|
||||
SavePlayer // Sent by the client, saves the player
|
||||
ServerFull // Sent by server when server has reached max connections
|
||||
|
||||
UnknownPacketType = 666
|
||||
)
|
||||
@ -49,6 +50,7 @@ func (n NetPacketType) String() string {
|
||||
CastSkill: "CastSkill",
|
||||
SpawnItem: "SpawnItem",
|
||||
SavePlayer: "SavePlayer",
|
||||
ServerFull: "ServerFull",
|
||||
}
|
||||
|
||||
return strings[n]
|
||||
|
38
d2networking/d2netpacket/packet_server_full.go
Normal file
38
d2networking/d2netpacket/packet_server_full.go
Normal file
@ -0,0 +1,38 @@
|
||||
package d2netpacket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
||||
)
|
||||
|
||||
// ServerFullPacket is sent by the server to inform a client that the
|
||||
// server has reached the max number of allowed connections.
|
||||
type ServerFullPacket struct{}
|
||||
|
||||
// CreateServerFullPacket returns a NetPacket which declares a ServerFullPacket.
|
||||
func CreateServerFullPacket() NetPacket {
|
||||
serverClosed := ServerFullPacket{}
|
||||
|
||||
b, err := json.Marshal(serverClosed)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
return NetPacket{
|
||||
PacketType: d2netpackettype.ServerFull,
|
||||
PacketData: b,
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalServerFull unmarshalls the given data to a ServerFullPacket struct
|
||||
func UnmarshalServerFull(packet []byte) (ServerFullPacket, error) {
|
||||
var resp ServerFullPacket
|
||||
|
||||
if err := json.Unmarshal(packet, &resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
@ -246,13 +246,13 @@ func (g *GameServer) handleConnection(conn net.Conn) {
|
||||
if err := g.registerConnection(packet.PacketData, conn); err != nil {
|
||||
switch err {
|
||||
case errServerFull: // Server is currently full and not accepting new connections.
|
||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/828
|
||||
log.Println(err)
|
||||
return
|
||||
_, errServerFullPacket := conn.Write(d2netpacket.MarshalPacket(d2netpacket.CreateServerFullPacket()))
|
||||
log.Println(errServerFullPacket)
|
||||
case errPlayerAlreadyExists: // Player is already registered and did not disconnection correctly.
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
connected = 1
|
||||
|
Loading…
Reference in New Issue
Block a user