コード例 #1
0
ファイル: Logic.go プロジェクト: sunminghong/wormhole
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
ファイル: player.go プロジェクト: sunminghong/wormhole
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Parse()

	c, err := iniconfig.ReadConfigFile(*clientConf)
	if err != nil {
		gts.Error(err.Error())
		return
	}

	section := "Default"

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

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

	var endianer gts.IEndianer
	endian, err := c.GetInt(section, "endian")
	if err == nil {
		endianer = gts.GetEndianer(endian)
	} else {
		endianer = gts.GetEndianer(gts.LittleEndian)
	}
	routepack := wormhole.NewRoutePack(endianer)
	var cwormholes wormhole.IWormholeManager

	client = wormhole.NewClient(clientTcpAddr, routepack, cwormholes, NewClientWormhole, wormhole.EWORMHOLE_TYPE_CLIENT)
	client.Connect()

	gts.Info("----------------client connect to %s,%s-----------------", clientTcpAddr)

	quit := make(chan bool)
	go exit(quit)

	<-quit
}
コード例 #3
0
ファイル: agent.go プロジェクト: sunminghong/wormhole
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)
}