コード例 #1
0
ファイル: warserver.go プロジェクト: Tactique/proxy
func Main() {
	porterIPString := flag.String("porterIP", "127.0.0.1", "Porter Server IP")
	porterPortString := flag.String("porterPort", ":5269", "Porter Server Port")
	portstring := flag.String("port", ":8888", "Server port")
	tcpportstring := flag.String("tcpport", ":11199", "TCP socket port")
	logpath := flag.String("logpath", "/dev/stderr", "Logging location")
	flag.Parse()

	port = PortMgmt.NewPortInfo(*portstring)
	tcpPort = PortMgmt.NewPortInfo(*tcpportstring)
	porterPort = PortMgmt.NewPortInfo(*porterPortString)
	porterIP = PortMgmt.IPString(*porterIPString)

	logger.SetupLoggerHelper(*logpath)

	if !verifyEnvironment() {
		logger.Fatalf("Please set $ROOTIQUE to your project root")
	}
	setupGamehub()

	go gamehub.handleConnections()

	go socketListen(tcpPort.Port)
	logger.Debugf("Socket listening on port %s", tcpPort)

	http.HandleFunc("/ws", serveWs)

	logger.Debugf("Http server listening on port %s", port)
	err := http.ListenAndServe(port.Port, nil)
	if err != nil {
		logger.Fatalf("ListenAndServe: %s", err.Error())
	}
}
コード例 #2
0
ファイル: gamehub.go プロジェクト: Tactique/proxy
func getClientIdFromToken(token string) (int, error) {
	dbPath := os.Getenv("ROOTIQUE") + "/common/database/db.sqlite3"
	db, err := sql.Open("sqlite3", dbPath)
	if err != nil {
		logger.Fatalf("%s", err)
	}
	defer db.Close()

	sql := fmt.Sprintf("select id, userid from interface_logindata where token='%s';", token)
	rows, err := db.Query(sql)
	if err != nil {
		return 0, err
	}
	var rowId int
	var userId int
	if rows.Next() {
		err := rows.Scan(&rowId, &userId)
		if err != nil {
			return 0, err
		}
	}
	if rows.Next() {
		return 0, errors.New("More than one entry returned in user query")
	}
	rows.Close()
	deleteRow := fmt.Sprintf("delete from interface_logindata where id='%s';", rowId)
	_, err = db.Exec(deleteRow)
	if err != nil {
		return 0, err
	}

	return userId, nil
}