Esempio n. 1
0
func (this *Session) RegisterProxy(address string, port uint16, motd string, version string, maxPlayers uint16) (ok bool) {
	sessionRegistry := this.server.SessionRegistry(ROLE_AUTHORIZED)
	if sessionRegistry.HasId(this.username) {
		ok = false
		return
	}
	if len(address) == 0 {
		address = this.remoteIp
	}
	this.Unregister()
	this.role = ROLE_PROXY
	this.roleAddress = address
	this.rolePort = port
	this.proxyMotd = motd
	this.proxyVersion = version
	this.proxyPlayers = make(map[string]uuid.UUID)
	this.proxyMaxPlayers = maxPlayers
	this.server.SessionRegistry(ROLE_AUTHORIZED).Register(this)
	this.server.SessionRegistry(ROLE_PROXY).Register(this)
	this.server.networkCache.RegisterProxy(this)
	for _, session := range this.server.SessionRegistry(ROLE_SERVER).GetAll() {
		this.Write(connect.NewPacketServerEventAdd(session.username, session.serverSecurityKey, session.roleAddress, session.rolePort))
	}
	ok = true
	return
}
Esempio n. 2
0
func (this *Session) RegisterServer(address string, port uint16) (ok bool) {
	sessionRegistry := this.server.SessionRegistry(ROLE_AUTHORIZED)
	if sessionRegistry.HasId(this.username) {
		ok = false
		return
	}
	if len(address) == 0 {
		address = this.remoteIp
	}
	securityKey, err := GenSalt()
	if err != nil {
		ok = false
		return
	}
	this.Unregister()
	this.role = ROLE_SERVER
	this.roleAddress = address
	this.rolePort = port
	this.serverSecurityKey = securityKey
	this.server.SessionRegistry(ROLE_AUTHORIZED).Register(this)
	this.server.SessionRegistry(ROLE_SERVER).Register(this)
	for _, session := range this.server.SessionRegistry(ROLE_PROXY).GetAll() {
		session.Write(connect.NewPacketServerEventAdd(this.username, this.serverSecurityKey, this.roleAddress, this.rolePort))
	}
	ok = true
	return
}