Exemplo n.º 1
0
func (gs *LGGateServer) InitFromConfig(
    configfile string,
    newPlayerConnection LGNewConnectionFunc, datagram LGIDatagram,
    newGridConnection LGNewConnectionFunc, dispatcher LGIDispatcher) {

    c, err := iniconfig.ReadConfigFile(configfile)
    if err != nil {
        LGError(err.Error())
        return
    }

    section := "Default"

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

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

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

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

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

    endian, err := c.GetInt(section, "endian")
    if err == nil {
        datagram.SetEndian(endian)
    } else {
        datagram.SetEndian(LGLittleEndian)
    }

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

    gs.Init(name, serverid, host, maxConnections,
        newPlayerConnection, datagram, newGridConnection, dispatcher,autoReconnectDuration)

}
Exemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Parse()

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

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

	logic := server.NewLogicFromIni(c, routepack, wormholes, NewLogicToAgent)

	logic.ConnectFromIni(c)

	gts.Info("----------------logic server is running!-----------------", logic.GetServerId())

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

	<-quit
}
Exemplo n.º 3
0
func (gs *LGGateServer) ConnectGrids(configfile *string) {
    c, err := iniconfig.ReadConfigFile(*configfile)
    if err != nil {
        LGError(err.Error())
        return
    }

    //make some connection to game server
    for i := 1; i < 50; i++ {
        section := "GridServer" + strconv.Itoa(i)
        if !c.HasSection(section) {
            continue
        }

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

        gname, err := c.GetString(section, "name")
        if err != nil {
            //if err.Reason == iniconfig.SectionNotFound {
            //    break
            //} else {
            LGError(err.Error())
            //    continue
            //}
            break
        }

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

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

        endian, err := c.GetInt(section, "endian")

        gs.gridConfs[gname] = &gridConf{gname, host, gCodes, endian, CONNECTION_STATE_FREE, nil}

        if err == nil {
            da := gs.Datagram.Clone(endian)
            gs.gridConfs[gname].datagram = da
            gs.ConnectGrid(gname, host, &gCodes, da)
        } else {
            gs.ConnectGrid(gname, host, &gCodes, nil)
        }
    }
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Parse()

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

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

	cwormholes := wormhole.NewWormholeManager(routepack, wormhole.MAX_CONNECTIONS, wormhole.EWORMHOLE_TYPE_CLIENT)

	dispatcher := server.NewDispatcher(routepack)
	lwormholes := server.NewLogicManager(routepack, dispatcher)
	agent := server.NewAgentFromIni(c, routepack, cwormholes, lwormholes, server.NewAgentToClientWormhole, server.NewAgentToLogicWormhole)

	agent.Start()

	gts.Info("----------------agent server is running!-----------------", agent.GetServerId())

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

	<-quit
}
Exemplo n.º 6
0
func (gs *LGGridServer) InitFromConfig(
	configfile string, newGridConnection LGNewConnectionFunc,
	datagram LGIDatagram) {

	c, err := iniconfig.ReadConfigFile(configfile)
	if err != nil {
		LGError(err.Error())
		return
	}

	section := "Default"

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

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

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

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

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

	allowDirectConnection, err := c.GetBool(section, "allowDirectConnection")
	if err != nil {
		allowDirectConnection = false
	}

	endian, err := c.GetInt(section, "endian")
	if err == nil {
		datagram.SetEndian(endian)
	} else {
		datagram.SetEndian(LGLittleEndian)
	}

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

	if profile > 0 {
		//LGSetMemProfileRate(1)
		//defer func() {
		//    LGGC()
		//    LGDumpHeap()
		//    LGPrintGCSummary()
		//}()
	}

	gs.Init(name, serverid, allowDirectConnection, host, maxConnections,
		newGridConnection, datagram)
}