<commit_before>package server

import (
	"flag"

	"math/rand"
	"time"

	"os"

	"io"

	_ "net/http/pprof"

	"net/http"

	"fmt"

	"runtime"

	"github.com/xiaonanln/goworld/components/dispatcher/dispatcher_client"
	"github.com/xiaonanln/goworld/config"
	"github.com/xiaonanln/goworld/entity"
	"github.com/xiaonanln/goworld/gwlog"
	"github.com/xiaonanln/goworld/gwutils"
	"github.com/xiaonanln/goworld/kvdb"
	"github.com/xiaonanln/goworld/netutil"
	"github.com/xiaonanln/goworld/proto"
	"github.com/xiaonanln/goworld/storage"
)

var (
	serverid    uint16
	configFile  string
	logLevel    string
	gameService *GameService
	gateService *GateService
)

func init() {
	parseArgs()
}

func parseArgs() {
	var serveridArg int
	flag.IntVar(&serveridArg, "sid", 0, "set serverid")
	flag.StringVar(&configFile, "configfile", "", "set config file path")
	flag.StringVar(&logLevel, "log", "", "set log level, will override log level in config")
	flag.Parse()
	serverid = uint16(serveridArg)
}

func Run(delegate IServerDelegate) {
	rand.Seed(time.Now().UnixNano())

	if configFile != "" {
		config.SetConfigFile(configFile)
	}

	serverConfig := config.GetServer(serverid)
	if serverConfig.GoMaxProcs > 0 {
		gwlog.Info("SET GOMAXPROCS = %d", serverConfig.GoMaxProcs)
		runtime.GOMAXPROCS(serverConfig.GoMaxProcs)
	}
	setupGWLog(logLevel, serverConfig)

	storage.Initialize()
	kvdb.Initialize()

	setupPprofServer(serverConfig)

	entity.SetSaveInterval(serverConfig.SaveInterval)

	gameService = newGameService(serverid, delegate)<commit_msg>intialize crontab in game routine<commit_after>package server

import (
	"flag"

	"math/rand"
	"time"

	"os"

	"io"

	_ "net/http/pprof"

	"net/http"

	"fmt"

	"runtime"

	"github.com/xiaonanln/goworld/components/dispatcher/dispatcher_client"
	"github.com/xiaonanln/goworld/config"
	"github.com/xiaonanln/goworld/crontab"
	"github.com/xiaonanln/goworld/entity"
	"github.com/xiaonanln/goworld/gwlog"
	"github.com/xiaonanln/goworld/gwutils"
	"github.com/xiaonanln/goworld/kvdb"
	"github.com/xiaonanln/goworld/netutil"
	"github.com/xiaonanln/goworld/proto"
	"github.com/xiaonanln/goworld/storage"
)

var (
	serverid    uint16
	configFile  string
	logLevel    string
	gameService *GameService
	gateService *GateService
)

func init() {
	parseArgs()
}

func parseArgs() {
	var serveridArg int
	flag.IntVar(&serveridArg, "sid", 0, "set serverid")
	flag.StringVar(&configFile, "configfile", "", "set config file path")
	flag.StringVar(&logLevel, "log", "", "set log level, will override log level in config")
	flag.Parse()
	serverid = uint16(serveridArg)
}

func Run(delegate IServerDelegate) {
	rand.Seed(time.Now().UnixNano())

	if configFile != "" {
		config.SetConfigFile(configFile)
	}

	serverConfig := config.GetServer(serverid)
	if serverConfig.GoMaxProcs > 0 {
		gwlog.Info("SET GOMAXPROCS = %d", serverConfig.GoMaxProcs)
		runtime.GOMAXPROCS(serverConfig.GoMaxProcs)
	}
	setupGWLog(logLevel, serverConfig)

	storage.Initialize()
	kvdb.Initialize()
	crontab.Initialize()

	setupPprofServer(serverConfig)

	entity.SetSaveInterval(serverConfig.SaveInterval)

	gameService = newGameService(serverid, delegate)
{'fraction_non_alphanumeric': 0.13241863433312062, 'fraction_numerical': 0.0038289725590299937, 'mean_word_length': 5.171259842519685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6785518', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1194, 'n_words': 187}