This commit is contained in:
azw 2023-08-13 15:07:33 +08:00
parent bc6d786b25
commit 17c149e8bf
6 changed files with 40 additions and 9 deletions

View File

@ -21,7 +21,7 @@ type WSPListener struct {
func (this *WSPListener) init() { func (this *WSPListener) init() {
this.ch = make(chan *f5.MsgHdr) this.ch = make(chan *f5.MsgHdr)
listener, err := net.Listen("tcp", "0.0.0.0:" + listener, err := net.Listen("tcp", "0.0.0.0:" +
q5.ToString(mt.Table.IMCluster.GetById(0).GetListenPort())) q5.ToString(mt.Table.IMCluster.GetListenPort()))
if err != nil { if err != nil {
} else { } else {

View File

@ -11,4 +11,19 @@ type IMCluster struct {
type IMClusterTable struct { type IMClusterTable struct {
f5.IdMetaTable[IMCluster] f5.IdMetaTable[IMCluster]
selfConf *IMCluster
}
func (this *IMCluster) Init1() {
}
func (this *IMClusterTable) GetListenPort() int32 {
return this.selfConf.GetListenPort()
}
func (this *IMClusterTable) PostInit1() {
this.selfConf = this.GetById(int64(f5.GetApp().GetInstanceId()))
if this.selfConf == nil {
panic("imserver集群无法读取本服配置")
}
} }

View File

@ -5,6 +5,7 @@ import (
) )
type IMCluster struct { type IMCluster struct {
instance_id int32
listen_port int32 listen_port int32
_flags1_ uint64 _flags1_ uint64
@ -20,12 +21,20 @@ type MasterCluster struct {
_flags2_ uint64 _flags2_ uint64
} }
func (this *IMCluster) GetInstanceId() int32 {
return this.instance_id
}
func (this *IMCluster) HasInstanceId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *IMCluster) GetListenPort() int32 { func (this *IMCluster) GetListenPort() int32 {
return this.listen_port return this.listen_port
} }
func (this *IMCluster) HasListenPort() bool { func (this *IMCluster) HasListenPort() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0 return (this._flags1_ & (uint64(1) << 2)) > 0
} }
func (this *MasterCluster) GetInstanceId() int32 { func (this *MasterCluster) GetInstanceId() int32 {
@ -54,7 +63,8 @@ func (this *MasterCluster) HasListenPort() bool {
func (this *IMCluster) LoadFromKv(kv map[string]interface{}) { func (this *IMCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 1, kv) f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 2, kv)
} }
func (this *MasterCluster) LoadFromKv(kv map[string]interface{}) { func (this *MasterCluster) LoadFromKv(kv map[string]interface{}) {

View File

@ -5,6 +5,7 @@ import (
"q5" "q5"
"f5" "f5"
"mt" "mt"
"fmt"
) )
type PlayerMgr struct { type PlayerMgr struct {
@ -16,7 +17,11 @@ func (this *PlayerMgr) init() {
1000, 1000,
func (e int32, args *q5.Args) { func (e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT { if e == q5.TIMER_EXEC_EVENT {
this.reportServerState() mt.Table.MasterCluster.Traverse(
func (meta *mt.MasterCluster) bool {
this.reportServerState(meta.GetIp(), meta.GetListenPort())
return true
})
} }
}) })
} }
@ -31,12 +36,12 @@ func (this *PlayerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg) wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
} }
func (this *PlayerMgr) reportServerState() { func (this *PlayerMgr) reportServerState(masterIp string, masterPort int32) {
params := map[string]string { params := map[string]string {
"node_id": q5.ToString(f5.GetApp().GetNodeId()), "node_id": q5.ToString(f5.GetApp().GetNodeId()),
"instance_id": q5.ToString(f5.GetApp().GetInstanceId()), "instance_id": q5.ToString(f5.GetApp().GetInstanceId()),
"ip": "", "ip": "",
"port": q5.ToString(mt.Table.IMCluster.GetById(0).GetListenPort()), "port": q5.ToString(mt.Table.IMCluster.GetListenPort()),
"online_num": q5.ToString(0), "online_num": q5.ToString(0),
"room_num": q5.ToString(0), "room_num": q5.ToString(0),
"channel": q5.ToString(0), "channel": q5.ToString(0),
@ -44,7 +49,7 @@ func (this *PlayerMgr) reportServerState() {
"servicing": q5.ToString(1), "servicing": q5.ToString(1),
} }
f5.GetHttpCliMgr().SendQuickChannelJsLikeRequest( f5.GetHttpCliMgr().SendQuickChannelJsLikeRequest(
"http://192.168.100.45:7821/webapp/index.php?c=GS&a=report&", fmt.Sprintf("http://%s:%d/webapp/index.php?c=GS&a=report&", masterIp, masterPort),
params, params,
func (rsp f5.HttpCliResponse) { func (rsp f5.HttpCliResponse) {
f5.GetSysLog().Info(rsp.GetRawData()) f5.GetSysLog().Info(rsp.GetRawData())

View File

@ -4,7 +4,8 @@ option go_package = ".;mt";
message IMCluster message IMCluster
{ {
optional int32 listen_port = 1; optional int32 instance_id = 1;
optional int32 listen_port = 2;
} }
message MasterCluster message MasterCluster

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit af8b11817827dfcb4deb7fe4f8c1b5bc4edb07d0 Subproject commit 36bf9bbc4c7fe8e66f2c194ad91781113e4a15cf