Пример #1
0
func NewLogicFromIni(
	c *iniconfig.ConfigFile,
	routepack IRoutePack, wm IWormholeManager,
	makeWormhole NewWormholeFunc) *Logic {

	section := "Default"

	logconf, err := c.GetString(section, "logConfigFile")
	if err != nil {
		logconf = ""
	}
	gts.SetLogger(&logconf)

	//start grid service
	name, err := c.GetString(section, "name")
	if err != nil {
		gts.Error(err.Error())
		return nil
	}

	serverId, err := c.GetInt(section, "serverId")
	if err != nil {
		gts.Error(err.Error())
		return nil
	}

	group, err := c.GetString(section, "group")
	if err != nil {
		group = "0"
	}

	/*
	   endian, err := c.GetInt(section, "endian")
	   if err == nil {
	       routepack.SetEndianer(gts.GetEndianer(endian))
	   } else {
	       routepack.SetEndianer(gts.GetEndianer(gts.LittleEndian))
	   }

	   autoDuration, err := c.GetInt(section, "autoReconnectDuration")
	   if err != nil {
	       autoDuration = 5
	   }
	   autoReconnectDuration := time.Duration(autoDuration) * time.Second
	*/

	ls := NewLogic(name, serverId, routepack, wm, makeWormhole, group)

	return ls
}
Пример #2
0
func (ls *Logic) ConnectFromIni(c *iniconfig.ConfigFile) {
	gts.Trace("connect from ini")
	//make some connection to game server
	for i := 1; i < 50; i++ {
		section := "Agent" + strconv.Itoa(i)
		if !c.HasSection(section) {
			continue
		}

		enabled, err := c.GetBool(section, "enabled")
		if err == nil && !enabled {
			continue
		}

		/*
		   serverId, err := c.GetInt(section, "serverId")
		   if err != nil {
		       gts.Error(err.Error())
		       continue
		   }

		   gname, err := c.GetString(section, "name")
		   if err != nil {
		       gts.Error(err.Error())
		       continue
		   }
		*/

		tcpAddr, err := c.GetString(section, "tcpAddr")
		if err != nil {
			gts.Error(err.Error())
			continue
		}

		ls.ConnectAgent(tcpAddr)
	}
}
Пример #3
0
func NewAgentFromIni(
	c *iniconfig.ConfigFile,
	routepack IRoutePack,
	clientWormholes IWormholeManager,
	logicWormholes IWormholeManager,
	makeClientWormhole NewWormholeFunc,
	makeLogicWormhole NewWormholeFunc) *Agent {

	section := "Default"

	logconf, err := c.GetString(section, "logConfigFile")
	if err != nil {
		logconf = ""
	}
	gts.SetLogger(&logconf)

	//start grid service
	name, err := c.GetString(section, "name")
	if err != nil {
		gts.Error(err.Error())
		return nil
	}

	serverId, err := c.GetInt(section, "serverId")
	if err != nil {
		gts.Error(err.Error())
		return nil
	}

	clientTcpAddr, err := c.GetString(section, "clientTcpAddr")
	if err != nil {
		gts.Error(err.Error())
		return nil
	}

	clientUdpAddr, err := c.GetString(section, "clientUdpAddr")
	if err != nil {
		gts.Warn(err.Error())
	}

	logicTcpAddr, err := c.GetString(section, "logicTcpAddr")
	if err != nil {
		gts.Error(err.Error())
		return nil
	}

	logicUdpAddr, err := c.GetString(section, "logicUdpAddr")
	if err != nil {
		gts.Warn(err.Error())
	}

	maxConnections, err := c.GetInt(section, "maxConnections")
	if err != nil {
		maxConnections = 1000
	}

	/*
	   endian, err := c.GetInt(section, "endian")
	   if err == nil {
	       routepack.SetEndianer(gts.GetEndianer(endian))
	   } else {
	       routepack.SetEndianer(gts.GetEndianer(gts.LittleEndian))
	   }

	   autoDuration, err := c.GetInt(section, "autoReconnectDuration")
	   if err != nil {
	       autoDuration = 5
	   }
	   autoReconnectDuration := time.Duration(autoDuration) * time.Second
	*/

	return NewAgent(
		name, serverId,
		clientTcpAddr, clientUdpAddr,
		logicTcpAddr, logicUdpAddr,
		maxConnections, routepack,
		clientWormholes,
		logicWormholes,
		makeClientWormhole,
		makeLogicWormhole)
}