Skip to content

Commit

Permalink
add sync arena season test code
Browse files Browse the repository at this point in the history
  • Loading branch information
hellodudu committed Oct 23, 2019
1 parent 7c2d495 commit 731d27a
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 155 deletions.
10 changes: 10 additions & 0 deletions game/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,3 +1107,13 @@ func (arena *Arena) APISyncSeason() interface{} {

return arena.wm.TestBroadCast(msg)
}

func (arena *Arena) TestSyncSeason() {
// broadcast to all world
msg := &pb.MUW_TestSyncArenaSeason{
Season: int32(arena.Season()),
EndTime: uint32(arena.SeasonEndTime()),
}
logger.Info("broadcast MUW_TestSyncArenaSeason with season:", msg.Season, ", endtime:", msg.EndTime)
arena.wm.BroadCast(msg)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/go-ini/ini v1.44.0
github.com/go-redis/redis v6.15.3+incompatible
github.com/go-sql-driver/mysql v1.4.1
github.com/gogo/protobuf v1.2.1
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/protobuf v1.3.2
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down
1 change: 1 addition & 0 deletions iface/igame.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type IArena interface {
GetRecordReqList() map[int64]uint32
APIRequestRank(id int64, page int) *pb.MUW_RequestArenaRank
APISyncSeason() interface{}
TestSyncSeason()
Season() int
SeasonEndTime() int
WeekEnd()
Expand Down
Binary file modified main
Binary file not shown.
350 changes: 199 additions & 151 deletions proto/world_message.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions proto/world_message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ message MUW_SyncArenaSeason {
uint32 end_time = 2;
}

message MUW_TestSyncArenaSeason {
int32 season = 1;
uint32 end_time = 2;
}

message ArenaWeeklyReward {
int64 player_id = 1;
int32 score = 2;
Expand Down
5 changes: 5 additions & 0 deletions server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (s *HttpServer) Run() {
http.HandleFunc("/arena_rank_list", s.arenaGetRankListHandler)
http.HandleFunc("/arena_api_request_rank", s.arenaAPIRequestRankHandler)
http.HandleFunc("/arena_api_sync_season", s.arenaAPISyncSeasonHandler)
http.HandleFunc("/arena_test_sync_season", s.arenaTestSyncSeasonHandler)
http.HandleFunc("/arena_save_champion", s.arenaSaveChampion)
http.HandleFunc("/arena_weekend", s.arenaWeekEnd)
http.HandleFunc("/player_info", s.getPlayerInfoHandler)
Expand Down Expand Up @@ -253,6 +254,10 @@ func (s *HttpServer) arenaAPISyncSeasonHandler(w http.ResponseWriter, r *http.Re
json.NewEncoder(w).Encode(d)
}

func (s *HttpServer) arenaTestSyncSeasonHandler(w http.ResponseWriter, r *http.Request) {
s.gm.Arena().TestSyncSeason()
}

func (s *HttpServer) arenaSaveChampion(w http.ResponseWriter, r *http.Request) {
s.gm.Arena().SaveChampion()
}
Expand Down
6 changes: 2 additions & 4 deletions world/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ func (w *world) SendProtoMessage(p proto.Message) {
copy(resp[14+len(typeName):], out)

// trace proto bug
if msg, ok := p.(*pb.MUW_RequestArenaRank); ok {
if msg.PlayerId == 1412159966747296018 {
logger.Warning("trace SendProtoMessage, 锅包肉's MUW_RequestArenaRank page:", msg.Page, ", rank:", msg.Rank, ", score:", msg.Score, ", proto_data:", resp)
}
if _, ok := p.(*pb.MUW_TestSyncArenaSeason); ok {
logger.Warning("trace MUW_TestSyncArenaSeason, world_id:", w.GetID(), ", resp:", resp)
}
// end trace

Expand Down
27 changes: 27 additions & 0 deletions world/world_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package world

import (
"encoding/binary"
"fmt"
"testing"

"github.com/gogo/protobuf/proto"
pb "github.com/hellodudu/Ultimate/proto"
)

func init() {

}

func TestUnmarshalRequestRank(t *testing.T) {

data := []byte{163, 2, 0, 0, 214, 57, 201, 199, 163, 2, 0, 0, 34, 0, 119, 111, 114, 108, 100, 95, 109, 101, 115, 115, 97, 103, 101, 46, 77, 85, 87, 95, 82, 101, 113, 117, 101, 115, 116, 65, 114, 101, 110, 97, 82, 97, 110, 107, 8, 146, 130, 128, 128, 160, 128, 192, 204, 19, 16, 4, 24, 6, 32, 238, 35, 40, 212, 134, 178, 237, 5, 50, 54, 8, 254, 131, 128, 128, 160, 128, 192, 164, 16, 18, 8, 230, 169, 153, 232, 156, 156, 194, 176, 26, 15, 83, 49, 45, 228, 184, 128, 230, 176, 148, 228, 184, 137, 230, 184, 133, 32, 206, 1, 40, 250, 212, 204, 136, 3, 48, 158, 1, 56, 124, 64, 172, 32, 50, 66, 8, 139, 136, 128, 128, 160, 128, 128, 182, 20, 18, 17, 233, 184, 162, 232, 175, 173, 230, 133, 149, 229, 144, 155, 229, 185, 180, 194, 176, 26, 17, 83, 49, 54, 49, 45, 229, 191, 131, 230, 131, 179, 228, 186, 139, 230, 136, 144, 32, 200, 1, 40, 133, 211, 133, 250, 2, 48, 247, 1, 56, 128, 1, 64, 172, 32, 50, 55, 8, 156, 135, 128, 128, 160, 128, 128, 234, 7, 18, 9, 231, 177, 179, 229, 164, 156, 231, 153, 189, 26, 15, 83, 49, 45, 228, 184, 137, 230, 184, 133, 230, 152, 190, 229, 140, 150, 32, 211, 1, 40, 183, 204, 188, 225, 2, 48, 151, 2, 56, 124, 64, 162, 32, 50, 60, 8, 195, 131, 128, 128, 160, 128, 192, 232, 16, 18, 12, 232, 130, 135, 228, 186, 139, 233, 128, 131, 233, 128, 184, 26, 17, 83, 49, 54, 49, 45, 233, 165, 174, 233, 169, 172, 230, 177, 159, 229, 141, 151, 32, 200, 1, 40, 142, 204, 182, 199, 2, 48, 155, 2, 56, 125, 64, 142, 32, 50, 63, 8, 149, 182, 128, 128, 160, 128, 128, 149, 16, 18, 15, 229, 166, 131, 228, 186, 166, 229, 144, 155, 230, 137, 128, 229, 177, 158, 26, 16, 83, 57, 55, 45, 229, 138, 159, 231, 155, 150, 229, 141, 131, 231, 167, 139, 32, 205, 1, 40, 154, 203, 153, 196, 2, 48, 158, 1, 56, 128, 1, 64, 250, 31, 50, 50, 8, 194, 140, 128, 128, 160, 128, 192, 182, 20, 18, 2, 206, 169, 26, 17, 83, 49, 54, 49, 45, 229, 191, 131, 230, 131, 179, 228, 186, 139, 230, 136, 144, 32, 200, 1, 40, 200, 196, 135, 183, 2, 48, 147, 1, 56, 89, 64, 250, 31, 50, 54, 8, 246, 137, 128, 128, 160, 128, 192, 224, 20, 18, 6, 232, 130, 165, 233, 184, 159, 26, 16, 83, 49, 55, 45, 231, 142, 137, 231, 190, 189, 229, 164, 169, 231, 169, 185, 32, 193, 1, 40, 233, 221, 214, 242, 2, 48, 148, 2, 56, 129, 1, 64, 250, 31, 50, 63, 8, 199, 182, 129, 128, 160, 128, 128, 240, 15, 18, 15, 230, 181, 129, 229, 185, 180, 230, 180, 151, 231, 155, 184, 230, 128, 157, 26, 16, 83, 51, 51, 45, 230, 184, 133, 233, 163, 142, 230, 152, 142, 230, 156, 136, 32, 209, 1, 40, 135, 222, 150, 251, 2, 48, 158, 2, 56, 128, 1, 64, 240, 31, 50, 62, 8, 143, 209, 128, 128, 160, 128, 192, 244, 7, 18, 15, 229, 134, 172, 229, 164, 169, 231, 154, 132, 229, 143, 182, 229, 173, 144, 26, 16, 83, 49, 55, 45, 233, 163, 142, 231, 148, 159, 230, 176, 180, 232, 181, 183, 32, 208, 1, 40, 137, 161, 234, 240, 2, 48, 206, 1, 56, 1, 64, 230, 31, 50, 61, 8, 173, 151, 128, 128, 160, 128, 128, 160, 16, 18, 15, 233, 154, 143, 229, 164, 156, 226, 152, 133, 232, 128, 140, 229, 174, 137, 26, 15, 83, 49, 45, 228, 184, 128, 230, 176, 148, 228, 184, 137, 230, 184, 133, 32, 205, 1, 40, 230, 177, 170, 232, 2, 48, 154, 2, 56, 118, 64, 230, 31}

newProto := &pb.MUW_RequestArenaRank{}
nameLen := binary.LittleEndian.Uint16(data[12 : 12+2])
if err := proto.Unmarshal(data[14+nameLen:], newProto); err != nil {
t.Error("Failed to parse MUW_RequestArenaRank", err)
}

fmt.Println("success unmarshal MUW_RequestArenaRank:", newProto)
}

0 comments on commit 731d27a

Please sign in to comment.