package internal

import (
	"github.com/name5566/leaf/gate"
)

var agents map[gate.Agent]struct{} // 所有玩家代理

func init() {
	agents = make(map[gate.Agent]struct{})

	// 注册RPC消息
	skeleton.RegisterChanRPC("NewAgent", rpcNewAgent)
	skeleton.RegisterChanRPC("CloseAgent", rpcCloseAgent)
}

// agent 被创建时
func rpcNewAgent(args []interface{}) {
	a := args[0].(gate.Agent)
	agents[a] = struct{}{}
}

// agent 被关闭时
func rpcCloseAgent(args []interface{}) {
	a := args[0].(gate.Agent)
	delete(agents, a)
}

// 广播
//for a := range agents {
//a.WriteMsg(msg)
//}
