修改娃娃机链接
This commit is contained in:
parent
07bea1ac2f
commit
be703582f6
|
|
@ -77,7 +77,11 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
|
||||||
|
|
||||||
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
||||||
if !ok || conn == nil {
|
if !ok || conn == nil {
|
||||||
return nil
|
fmt.Println("移动,创建链接!!!!!!!!!!!!!")
|
||||||
|
conn = machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||||
|
if conn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg.Perate {
|
switch msg.Perate {
|
||||||
|
|
@ -119,6 +123,7 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
|
||||||
Process(conn, f1, f2)
|
Process(conn, f1, f2)
|
||||||
case 5:
|
case 5:
|
||||||
//投币
|
//投币
|
||||||
|
conn := machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||||
fmt.Println("===========玩家投币===========", conn)
|
fmt.Println("===========玩家投币===========", conn)
|
||||||
go DollMachineGrabResult(conn, msg.Snid, msg.GetId())
|
go DollMachineGrabResult(conn, msg.Snid, msg.GetId())
|
||||||
machinedoll.Coin(conn)
|
machinedoll.Coin(conn)
|
||||||
|
|
@ -137,7 +142,11 @@ func SMDollMachineGrabHandler(session *netlib.Session, packetId int, data interf
|
||||||
|
|
||||||
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
||||||
if !ok || conn == nil {
|
if !ok || conn == nil {
|
||||||
return nil
|
fmt.Println("下抓,创建链接!!!!!!!!!!!!!")
|
||||||
|
conn = machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||||
|
if conn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg.GetTypeId() {
|
switch msg.GetTypeId() {
|
||||||
|
|
@ -198,6 +207,13 @@ func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) {
|
||||||
Result: 0,
|
Result: 0,
|
||||||
TypeId: 2,
|
TypeId: 2,
|
||||||
})
|
})
|
||||||
|
//删除娃娃机链接
|
||||||
|
//delete(machinedoll.MachineMgr.ConnMap, conn.Id)
|
||||||
|
err := conn.Conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("关闭与娃娃机链接")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Contains(part, instruction1) && num != 1 {
|
if bytes.Contains(part, instruction1) && num != 1 {
|
||||||
|
|
@ -215,6 +231,13 @@ func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) {
|
||||||
Result: 1,
|
Result: 1,
|
||||||
TypeId: 2,
|
TypeId: 2,
|
||||||
})
|
})
|
||||||
|
//删除娃娃机链接
|
||||||
|
//delete(machinedoll.MachineMgr.ConnMap, conn.Id)
|
||||||
|
err := conn.Conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("关闭与娃娃机链接")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//上分成功
|
//上分成功
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,47 @@ func (this *MachineManager) Init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建娃娃机链接
|
||||||
|
func (this *MachineManager) CreateConn(key int) *Conn {
|
||||||
|
fmt.Println("新建与娃娃机链接")
|
||||||
|
var serverAddrs []string
|
||||||
|
programDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Error("Error getting working directory:", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
configFile := filepath.Join(programDir, "machineIPConfig.json")
|
||||||
|
logger.Logger.Trace("构建配置文件的路径", configFile)
|
||||||
|
fileData, err := os.ReadFile(configFile)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Error("Read robot account file error:", err)
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
if err = json.Unmarshal(fileData, &serverAddrs); err != nil {
|
||||||
|
logger.Logger.Error("Unmarshal robot account data error:", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//与娃娃机创建连接
|
||||||
|
// 遍历每个服务器地址,建立连接
|
||||||
|
for i, addr := range serverAddrs {
|
||||||
|
if i+1 == key {
|
||||||
|
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Error("Failed to connect to server:", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.ConnMap[i+1] = &Conn{
|
||||||
|
Id: i + 1,
|
||||||
|
Conn: conn,
|
||||||
|
Addr: addr,
|
||||||
|
}
|
||||||
|
return this.ConnMap[i+1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (this *MachineManager) Update() {
|
func (this *MachineManager) Update() {
|
||||||
//向游戏服发送心跳包
|
//向游戏服发送心跳包
|
||||||
pack := &machine.MSDollMachineHeartBeat{}
|
pack := &machine.MSDollMachineHeartBeat{}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue