thrift GM服务器

This commit is contained in:
hahwu 2026-03-05 17:51:03 +08:00
parent 0e01178669
commit 385d571c3a
6 changed files with 1 additions and 2712 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ src/server/test/logs/*
src/server/test/teLog/*
src/server/*.exe*
src/server/msg/Gameapi.pb.go
src/server/gen-go

View File

@ -1,52 +0,0 @@
namespace go backend
struct ResAdminInfo{
1: string Name,
2: i64 Uid,
3: i32 AreaId,
4: i32 Face;
5: double Charge;
6: double MaxCharge;
7: i32 Level;
8: i32 Diamond;
9: i32 Star;
10: i32 Energy;
11: string UserName;
12: i64 LoginTime;
13: i32 Cumulative;
14: i32 RegisterTime;
15: i8 Ban;
16: i32 TodayCumulative;
17: i32 Bouns;
18: string Code;
19: map<string, i32> ChessMap;
20: list<Actlog> ActLog;
21: list<FriendInfo> FriendList;
22: map<i32,OrderInfo> OrderList;
}
struct Actlog{
1: i8 Type;
2: i64 Time;
3: string Param;
}
struct OrderInfo{
1: i32 Id;
2: i32 Type;
3: i64 Time;
4: string ChessId;
5: i8 Diff;
}
struct FriendInfo{
1: i64 Uid;
2: string NickName;
3: i32 Level;
4: i64 LogoutTime;
5: i64 LoginTime;
6: i32 Face;
}
service GameAdminService{
ResAdminInfo GetAdminInfo(1:i32 Uid);
}

View File

@ -1,6 +0,0 @@
// Code generated by Thrift Compiler (0.22.0). DO NOT EDIT.
package backend
var GoUnusedProtection__ int;

View File

@ -1,34 +0,0 @@
// Code generated by Thrift Compiler (0.22.0). DO NOT EDIT.
package backend
import (
"bytes"
"context"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
func init() {
}

File diff suppressed because it is too large Load Diff

View File

@ -1,164 +0,0 @@
// Code generated by Thrift Compiler (0.22.0). DO NOT EDIT.
package main
import (
"context"
"flag"
"fmt"
"math"
"net"
"net/url"
"os"
"strconv"
"strings"
thrift "github.com/apache/thrift/lib/go/thrift"
"server/gen-go/backend"
)
var _ = backend.GoUnusedProtection__
func Usage() {
fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:")
flag.PrintDefaults()
fmt.Fprintln(os.Stderr, "\nFunctions:")
fmt.Fprintln(os.Stderr, " ResAdminInfo GetAdminInfo(i32 Uid)")
fmt.Fprintln(os.Stderr)
os.Exit(0)
}
type httpHeaders map[string]string
func (h httpHeaders) String() string {
var m map[string]string = h
return fmt.Sprintf("%s", m)
}
func (h httpHeaders) Set(value string) error {
parts := strings.Split(value, ": ")
if len(parts) != 2 {
return fmt.Errorf("header should be of format 'Key: Value'")
}
h[parts[0]] = parts[1]
return nil
}
func main() {
flag.Usage = Usage
var host string
var port int
var protocol string
var urlString string
var framed bool
var useHttp bool
headers := make(httpHeaders)
var parsedUrl *url.URL
var trans thrift.TTransport
_ = strconv.Atoi
_ = math.Abs
flag.Usage = Usage
flag.StringVar(&host, "h", "localhost", "Specify host and port")
flag.IntVar(&port, "p", 9090, "Specify port")
flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
flag.StringVar(&urlString, "u", "", "Specify the url")
flag.BoolVar(&framed, "framed", false, "Use framed transport")
flag.BoolVar(&useHttp, "http", false, "Use http")
flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H \"Key: Value\")")
flag.Parse()
if len(urlString) > 0 {
var err error
parsedUrl, err = url.Parse(urlString)
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
host = parsedUrl.Host
useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https"
} else if useHttp {
_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
if err != nil {
fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
flag.Usage()
}
}
cmd := flag.Arg(0)
var err error
var cfg *thrift.TConfiguration = nil
if useHttp {
trans, err = thrift.NewTHttpClient(parsedUrl.String())
if len(headers) > 0 {
httptrans := trans.(*thrift.THttpClient)
for key, value := range headers {
httptrans.SetHeader(key, value)
}
}
} else {
portStr := fmt.Sprint(port)
if strings.Contains(host, ":") {
host, portStr, err = net.SplitHostPort(host)
if err != nil {
fmt.Fprintln(os.Stderr, "error with host:", err)
os.Exit(1)
}
}
trans = thrift.NewTSocketConf(net.JoinHostPort(host, portStr), cfg)
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
if framed {
trans = thrift.NewTFramedTransportConf(trans, cfg)
}
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating transport", err)
os.Exit(1)
}
defer trans.Close()
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg)
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg)
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryConf(cfg)
default:
fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
Usage()
os.Exit(1)
}
iprot := protocolFactory.GetProtocol(trans)
oprot := protocolFactory.GetProtocol(trans)
client := backend.NewGameAdminServiceClient(thrift.NewTStandardClient(iprot, oprot))
if err := trans.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
switch cmd {
case "GetAdminInfo":
if flag.NArg() - 1 != 1 {
fmt.Fprintln(os.Stderr, "GetAdminInfo requires 1 args")
flag.Usage()
}
tmp0, err18 := (strconv.Atoi(flag.Arg(1)))
if err18 != nil {
Usage()
return
}
argvalue0 := int32(tmp0)
value0 := argvalue0
fmt.Print(client.GetAdminInfo(context.Background(), value0))
fmt.Print("\n")
break
case "":
Usage()
default:
fmt.Fprintln(os.Stderr, "Invalid function ", cmd)
}
}