Compare commits

..

No commits in common. "1961caad122ccd4cfc25e189a26b958c1a602c17" and "4cfd64dbedffe3a295157444bc0b87862668fc6d" have entirely different histories.

2 changed files with 42 additions and 38 deletions

View File

@ -119,8 +119,8 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
Process(conn, f1, f2) Process(conn, f1, f2)
case 5: case 5:
//投币 //投币
fmt.Println("===========玩家投币===========", conn) fmt.Println("===========玩家投币===========")
go DollMachineGrabResult(conn, msg.Snid, msg.GetId()) go DollMachineGrabResult(session, conn, msg.Snid, msg.GetId())
machinedoll.Coin(conn) machinedoll.Coin(conn)
} }
@ -162,7 +162,7 @@ func SMDollMachineGrabHandler(session *netlib.Session, packetId int, data interf
} }
// 监听抓取结果返回 // 监听抓取结果返回
func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) { func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid, id int32) {
num := int64(1) num := int64(1)
for { for {
// 读取数据 // 读取数据

View File

@ -10,9 +10,11 @@ import (
"syscall" "syscall"
"time" "time"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/module"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
"mongo.games.com/goserver/core/task"
"mongo.games.com/goserver/srvlib" "mongo.games.com/goserver/srvlib"
"mongo.games.com/game/protocol/machine" "mongo.games.com/game/protocol/machine"
@ -88,48 +90,48 @@ func (this *MachineManager) Init() {
} }
func (this *MachineManager) Update() { func (this *MachineManager) Update() {
/* var delConn []*Conn var delConn []*Conn
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
for _, v := range this.ConnMap {
_, err := v.Write([]byte("heartbeat"))
if err != nil {
delConn = append(delConn, v)
v.Close()
logger.Logger.Tracef("断开连接:%v", v.Addr)
this.UpdateToGameServer(v, 0)
}
}
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
for _, v := range delConn {
delete(this.ConnMap, v.Id)
this.DelConnMap[v.Id] = v.Addr
}
// 重连
var delIds []*Conn
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
for _, v := range this.ConnMap { for id, addr := range this.DelConnMap {
_, err := v.Write([]byte("heartbeat")) conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
if err != nil { if err != nil {
delConn = append(delConn, v) continue
v.Close()
fmt.Println("断开连接:%v", v.Addr)
this.UpdateToGameServer(v, 0)
} }
logger.Logger.Tracef("娃娃机重连成功addr = %v", addr)
delIds = append(delIds, &Conn{
Id: id,
Conn: conn,
Addr: addr,
})
} }
return nil return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
for _, v := range delConn { for _, v := range delIds {
delete(this.ConnMap, v.Id) this.ConnMap[v.Id] = v
this.DelConnMap[v.Id] = v.Addr delete(this.DelConnMap, v.Id)
this.UpdateToGameServer(v, 1)
} }
})).StartByFixExecutor(this.ModuleName())
// 重连 })).StartByFixExecutor(this.ModuleName())
var delIds []*Conn
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
for id, addr := range this.DelConnMap {
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
if err != nil {
continue
}
fmt.Println("娃娃机重连成功addr = %v", addr)
delIds = append(delIds, &Conn{
Id: id,
Conn: conn,
Addr: addr,
})
}
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
for _, v := range delIds {
this.ConnMap[v.Id] = v
delete(this.DelConnMap, v.Id)
this.UpdateToGameServer(v, 1)
}
})).StartByFixExecutor(this.ModuleName())
})).StartByFixExecutor(this.ModuleName())*/
} }
func (this *MachineManager) Shutdown() { func (this *MachineManager) Shutdown() {
@ -202,6 +204,8 @@ func listenKeyboardEvents(conn net.Conn) {
case "j": case "j":
Grab(conn) Grab(conn)
case "J": case "J":
SetPower(conn)
time.Sleep(200 * time.Millisecond)
Grab(conn) Grab(conn)
case "k": case "k":