修改娃娃机链接
This commit is contained in:
parent
07bea1ac2f
commit
be703582f6
|
|
@ -77,8 +77,12 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
|
|||
|
||||
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
||||
if !ok || conn == nil {
|
||||
fmt.Println("移动,创建链接!!!!!!!!!!!!!")
|
||||
conn = machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||
if conn == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
switch msg.Perate {
|
||||
case 1:
|
||||
|
|
@ -119,6 +123,7 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
|
|||
Process(conn, f1, f2)
|
||||
case 5:
|
||||
//投币
|
||||
conn := machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||
fmt.Println("===========玩家投币===========", conn)
|
||||
go DollMachineGrabResult(conn, msg.Snid, msg.GetId())
|
||||
machinedoll.Coin(conn)
|
||||
|
|
@ -137,8 +142,12 @@ func SMDollMachineGrabHandler(session *netlib.Session, packetId int, data interf
|
|||
|
||||
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
||||
if !ok || conn == nil {
|
||||
fmt.Println("下抓,创建链接!!!!!!!!!!!!!")
|
||||
conn = machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||
if conn == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
switch msg.GetTypeId() {
|
||||
case 1:
|
||||
|
|
@ -198,6 +207,13 @@ func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) {
|
|||
Result: 0,
|
||||
TypeId: 2,
|
||||
})
|
||||
//删除娃娃机链接
|
||||
//delete(machinedoll.MachineMgr.ConnMap, conn.Id)
|
||||
err := conn.Conn.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("关闭与娃娃机链接")
|
||||
return
|
||||
}
|
||||
if bytes.Contains(part, instruction1) && num != 1 {
|
||||
|
|
@ -215,6 +231,13 @@ func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) {
|
|||
Result: 1,
|
||||
TypeId: 2,
|
||||
})
|
||||
//删除娃娃机链接
|
||||
//delete(machinedoll.MachineMgr.ConnMap, conn.Id)
|
||||
err := conn.Conn.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("关闭与娃娃机链接")
|
||||
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() {
|
||||
//向游戏服发送心跳包
|
||||
pack := &machine.MSDollMachineHeartBeat{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue