Exemple #1
0
func main() {
	//	flag.Parse()
	//console.Init()
	config.Parse()
	golog.SetLevel(golog.LevelDebug)

	srvModule := NewServer()
	srvModule.Start()
	golog.Info("main", "main", "Starting server", "addr", *config.FLAG_ADDR)

	c := make(chan os.Signal, 1)
	signal.Notify(c,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT,
		syscall.SIGKILL)
	//	signal.Notify(c, os.Interrupt, os.Kill)

	sig := <-c
	golog.Info("main", "main", "Server begin close", "sig", sig)

	golog.Info("main", "main", "Closing server module ...")
	srvModule.Close()

	golog.Info("main", "main", "Server close success")
}
Exemple #2
0
func Init() {
	golog.Info("Init", "Init", "-------init db driver")
	driver.Init()

	golog.Info("Init", "Init", "-------init player session manager")
	G_playerSessionMgr = NewPlayerSessionManager()

	//golog.Info("Init", "Init", "-------init socket dispatcher")
	//	G_dispatcher = NewDispatch()

	golog.Info("Init", "Init", "-------init socket server")
	G_sockServer = NewSocketServer("Socket Server", *config.FLAG_ADDR, 10000000)
}
Exemple #3
0
func NewDispatch() *Dispatcher {
	golog.Info("Init", "Init", "-------init socket dispatcher")
	disp := &Dispatcher{
		register: make(map[int32]IServlet),
	}
	return disp
}
Exemple #4
0
func AccessMongo(session *mgo.Session, loginId string) {

	/*
		c := session.DB("card").C("role")
		pipe := c.Pipe([]bson.M{
			bson.M{"$match": bson.M{"level": bson.M{"$gte": 1}}},
			bson.M{"$group": bson.M{"_id": "$loginid", "total": bson.M{"$sum": "$money"}}},
			bson.M{"$sort": bson.M{"total": -1}},
		})
		resp := []bson.M{}
		err := pipe.All(&resp)
		if err != nil {
			//handle error
		}
	*/
	c := session.DB("card").C("role")
	var result interface{}
	err := c.Find(bson.M{"loginid": "g001_28_282843150017"}).One(&result)
	if err != nil {
		//		log.Fatal(err)
	}

	mongocount++
	if mongocount%1000 == 0 {
		golog.Info("AccessMongo", "AccessMongo", "Access mongo over", "count", mongocount)
	}
	//	for _, v := range resp {
	//		fmt.Println("loginid", v["_id"], "sum", v["total"])
	//	}
}
Exemple #5
0
func (ps *PlayerSession) Reader() {
	defer func() {
		msg := recover()
		if msg != nil {
			golog.Error("PlayerSession", "Reader", "throw error", "msg", msg)
			ps.close = true
		}
	}()
	for {
		//		golog.Debug("PlayerSession", "Reader", "Cycle reading", "cnt", cnt)
		if ps.close == true {
			golog.Info("PlayerSession", "Reader", "Session closed")
			break
		}

		data, err := ps.readPacket()
		if err != nil {
			if err == io.EOF {
				golog.Debug("PlayerSession", "Reader", "client disconnected",
					"err", err, "addr", ps.conn.RemoteAddr().String())
			} else {
				golog.Error("PlayerSession", "Reader", "Unable to read packet", "err", err)
			}
			ps.close = true
			return
		}
		//if encryption, do decryption
		decrData := ps.decrypt(data)

		if ok := ps.dispatch(decrData); !ok {
			ps.close = true
			return
		}
	}
}
Exemple #6
0
func AccessPostgresql(db *sql.DB, loginId string) {
	defer func() {
		msg := recover()
		if msg != nil {
			golog.Error("1", "1", "1", "msg", msg)
			panic(msg)
		}
	}()
	/*
		rows, err := db.Query("select loginname,accname from account limit 3") //"SELECT name FROM users WHERE age = $1", age)
		//	var cnt int
		//	err := db.QueryRow("select count(*) from account").Scan(&cnt)
		if err != nil {
			golog.Error("AccessPostgresql", "AccessPostgresql", "Access postgresql query", "err", err)
		}
		//	golog.Info("AccPostgres", "", "", "cnt", cnt, "loginId", loginId)

		defer rows.Close()
		var accname, loginname string
		for rows.Next() {
			err = rows.Scan(&loginname, &accname)
			if err != nil {
				golog.Error("AccessPostgresql", "AccessPostgresql", "Access postgresql scan", "err", err)
			}
			golog.Info("AccessPostgresql", "AccessPostgresql", "Access postgresql over", "loginname", loginname, "accname", accname)
		}
	*/

	var stmt *sql.Stmt
	var err error

	stmt, err = db.Prepare("select loginname,accname from account limit 3")
	if err != nil {
		golog.Error("AccessPostgresql", "AccessPostgresql", "Access postgresql prepare", "err", err)
		return
	}

	var rows *sql.Rows

	rows, err = stmt.Query()
	if err != nil {
		golog.Error("AccessPostgresql", "AccessPostgresql", "Access postgresql query", "err", err)
		return
	}

	defer stmt.Close()

	for rows.Next() {
		var loginname, accname string
		err = rows.Scan(&loginname, &accname)
		if err != nil {
			golog.Error("AccessPostgresql", "AccessPostgresql", "Access postgresql scan", "err", err)
			return
		}

		//			golog.Info("AccessPostgresql", "AccessPostgresql", "Access postgresql over", "loginname", loginname, "accname", accname)
	}
	count++
	if count%1000 == 0 {
		golog.Info("AccessPostgresql", "AccessPostgresql", "Access postgresql over", "count", count)
	}
}
Exemple #7
0
func AccessRedis(loginId string, ts int32) {
	defer func() {
		msg := recover()
		if msg != nil {
			panic(msg)
		}
	}()
	conn := driver.RedisPool.Get()
	defer conn.Close()

	_, err := conn.Do("MULTI")
	if err != nil {
		golog.Error("AccessRedis", "AccessRedis", "DO MULTI", "msg", err)
		panic(err)
	}

	_, err = conn.Do("hget", "rank_arena_hash", "AI5653f448aff8bc6d00002351")
	if err != nil {
		golog.Error("AccessRedis", "AccessRedis", "DO hgetall", "msg", err)
		panic(err)
	}
	/*
		_, err = conn.Do("lrange", "rank_arena_list", 0, -1)
		if err != nil {
			golog.Error("AccessRedis", "AccessRedis", "Do lrange", "msg", err)
			panic(err)
		}
	*/
	_, err = conn.Do("EXEC")
	if err != nil {
		golog.Error("AccessRedis", "AccessRedis", "Do EXEC", "msg", err)
		panic(err)
	}
	rediscount++
	if rediscount%1000 == 0 {
		golog.Info("AccessRedis", "AccessRedis", "Access redis over", "count", rediscount)
	}

	/*
		results, err := redis.MultiBulk(reply, err)
		if err != nil {
			golog.Error("AccessRedis", "AccessRedis", "multibulk err", "msg", err)
			panic(err)
		}
		if len(results) < 2 {
			golog.Error("AccessRedis", "AccessRedis", "results len error", "len", len(results), "loginid", loginId, "index", ts)
			panic("results array len error")
		}
	*/
	/*
		{
			_, err := redis.IntMap(results[0], err)
				for k, v := range intMap {
					//fmt.Println(k, v)
					//golog.Debug("AccessRedis", "AccessRedis", "hgetall rank_arena_hash", "k", k, "v", v)
				}
			_, err = redis.Strings(results[1], err)
				for _, _ = range strs {
					//fmt.Println("lrange", val)
					//golog.Debug("AccessRedis", "AccessRedis", "lrange rank_arena_list", "val", val)
				}
		}
	*/
}
Exemple #8
0
func Init() {
	golog.Info("Init", "Init", "-------init db driver")
	PGPool = newPostgres()
	RedisPool = newPool(*config.FLAG_REDIS_ADDR, *config.FLAG_REDIS_PASSWD)
	Mgo = newMongo()
}