上传协议测试工具代码

This commit is contained in:
liwei1dao 2022-06-30 15:12:01 +08:00
parent 4cd4b89be6
commit 0c3cf4b7a1
22 changed files with 1412 additions and 252 deletions

22
package-lock.json generated
View File

@ -11,6 +11,8 @@
"@mdi/font": "5.9.55", "@mdi/font": "5.9.55",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"google-protobuf": "^3.20.1", "google-protobuf": "^3.20.1",
"js-base64": "^3.7.2",
"js-md5": "^0.7.3",
"protobufjs": "^6.11.3", "protobufjs": "^6.11.3",
"roboto-fontface": "*", "roboto-fontface": "*",
"vue": "^3.2.13", "vue": "^3.2.13",
@ -7527,6 +7529,16 @@
"@sideway/pinpoint": "^2.0.0" "@sideway/pinpoint": "^2.0.0"
} }
}, },
"node_modules/js-base64": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.2.tgz",
"integrity": "sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ=="
},
"node_modules/js-md5": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz",
"integrity": "sha512-ZC41vPSTLKGwIRjqDh8DfXoCrdQIyBgspJVPXHBGu4nZlAEvG3nf+jO9avM9RmLiGakg7vz974ms99nEV0tmTQ=="
},
"node_modules/js-message": { "node_modules/js-message": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz", "resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz",
@ -17862,6 +17874,16 @@
"@sideway/pinpoint": "^2.0.0" "@sideway/pinpoint": "^2.0.0"
} }
}, },
"js-base64": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.2.tgz",
"integrity": "sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ=="
},
"js-md5": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz",
"integrity": "sha512-ZC41vPSTLKGwIRjqDh8DfXoCrdQIyBgspJVPXHBGu4nZlAEvG3nf+jO9avM9RmLiGakg7vz974ms99nEV0tmTQ=="
},
"js-message": { "js-message": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz", "resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz",

View File

@ -11,6 +11,8 @@
"@mdi/font": "5.9.55", "@mdi/font": "5.9.55",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"google-protobuf": "^3.20.1", "google-protobuf": "^3.20.1",
"js-base64": "^3.7.2",
"js-md5": "^0.7.3",
"protobufjs": "^6.11.3", "protobufjs": "^6.11.3",
"roboto-fontface": "*", "roboto-fontface": "*",
"vue": "^3.2.13", "vue": "^3.2.13",

File diff suppressed because it is too large Load Diff

View File

@ -18,15 +18,17 @@ message AgentMessage {
string UserSessionId = 2; string UserSessionId = 2;
string UserId = 3; string UserId = 3;
string GatewayServiceId = 4; string GatewayServiceId = 4;
string Method = 5; string MainType = 5;
google.protobuf.Any Message = 6; string SubType = 6;
google.protobuf.Any Message = 7;
} }
// RPC // RPC
message RPCMessageReply { message RPCMessageReply {
ErrorCode Code = 1; ErrorCode Code = 1;
string Message = 2; string ErrorMessage = 2;
string Data = 3; string ErrorData = 3;
repeated UserMessage Reply = 4;
} }
//Uid请求 //Uid请求
@ -63,3 +65,15 @@ message BroadCastMessageReq {
// //
message AgentCloseeReq { string UserSessionId = 1; } message AgentCloseeReq { string UserSessionId = 1; }
//线
message NoticeUserCloseReq {string UserSessionId = 1; string UserId = 2; }
//
enum HeroAttributesType{
Hp = 0; //
Atk = 1; //
Def = 2; //
Speed = 3; //
Crit = 4; //
}

View File

@ -0,0 +1,25 @@
syntax = "proto3";
option go_package = ".;pb";
//
message EquipmentAttributeEntry {
int32 Id = 1; //id
int32 libraryid = 2; //id
string AttrName = 3; //
int32 Lv = 4; //
int32 Value = 5; //
}
//
message DB_Equipment {
string Id = 1; //@go_tags(`bson:"_id"`) id
sint32 cId = 2; //@go_tags(`bson:"cId"`) Id
string uId = 3; //@go_tags(`bson:"uid"`) Id
string heroId = 5; //@go_tags(`bson:"heroId"`) id ''
sint32 lv = 6; //@go_tags(`bson:"lv"`)
sint32 keepFailNum = 7; //@go_tags(`bson:"keepFailNum"`)
EquipmentAttributeEntry mainEntry = 8; //@go_tags(`bson:"mainEntry"`)
repeated EquipmentAttributeEntry adverbEntry = 9; //@go_tags(`bson:"adverbEntry"`)
uint32 overlayNum = 10; //@go_tags(`bson:"overlayNum"`)
bool isInitialState = 11; //@go_tags(`bson:"isInitialState"`)
}

View File

@ -0,0 +1,33 @@
syntax = "proto3";
option go_package = ".;pb";
import "equipment_db.proto";
//
message EquipmentGetListReq {
}
//
message EquipmentGetListResp {
repeated DB_Equipment Equipments = 1; //
}
//
message EquipmentEquipReq{
string HeroCardId = 1; //Id
repeated string EquipmentId = 2; //Id 0-5
}
//
message EquipmentEquipResp{
}
//
message EquipmentUpgradeReq{
string EquipmentId = 1; //Id
}
//
message EquipmentUpgradeResp{
}

View File

@ -17,11 +17,18 @@ enum ErrorCode {
DBError = 21; // DBError = 21; //
SystemError = 22; // SystemError = 22; //
Exception = 100; // Exception = 100; //
Unknown = 101; //
ResNoEnough = 102; //
ConfigurationException = 103; //
ConfigNoFound = 104; //
// user // user
SecKeyInvalid = 1000; // SecKeyInvalid = 1000; //
SecKey = 1001; // SecKey = 1001; //
BindUser = 1002; // BindUser = 1002; //
GoldNoEnough = 1003; //
DiamondNoEnough = 1004; //
RoleCreated = 1005; //
// friend // friend
FriendNotSelf = 1100; // FriendNotSelf = 1100; //
@ -36,4 +43,28 @@ enum ErrorCode {
FriendApplyError = 1109; // FriendApplyError = 1109; //
FriendBlackMax = 1110; // FriendBlackMax = 1110; //
FriendSearchNameEmpty = 1111; // FriendSearchNameEmpty = 1111; //
// item
ItemsNoEnough = 1200; //
ItemsNoFoundGird = 1201; //
ItemsGridNumUpper = 1202; //
ItemsGirdAmountUpper = 1203; //
// hero
HeroNoExist = 1300; //
HeroNoEnough = 1301; //
HeroMaxLv = 1302; //
HeroInitCreat = 1303; //
HeroColorErr = 1304; //
HeroSkillUpErr = 1305;//
HeroMaxResonate = 1306; //
HeroNoResonate = 1307; //
HeroNotNeedResonate = 1308; //
HeroNoEnergy = 1309; //
HeroCreate = 1310; //
// equipment
EquipmentOnFoundEquipment = 1400; //
EquipmentLvlimitReached = 1401; //
} }

View File

@ -0,0 +1,3 @@
syntax = "proto3";
option go_package = ".;pb";

View File

@ -0,0 +1,2 @@
syntax = "proto3";
option go_package = ".;pb";

View File

@ -1,7 +1,7 @@
syntax = "proto3"; syntax = "proto3";
option go_package = ".;pb"; option go_package = ".;pb";
message DB_FriendData { message DBFriend {
string uId = 1; //@go_tags(`bson:"uId"`) ID string uId = 1; //@go_tags(`bson:"uId"`) ID
repeated string friendIds = 2; //@go_tags(`bson:"friendIds"`) ID repeated string friendIds = 2; //@go_tags(`bson:"friendIds"`) ID
repeated string applyIds = 3; //@go_tags(`bson:"applyIds"`) ID repeated string applyIds = 3; //@go_tags(`bson:"applyIds"`) ID

View File

@ -12,97 +12,97 @@ message FriendBase {
} }
// //
message Friend_List_Req {} message FriendListReq {}
message Friend_List_Rsp { repeated FriendBase list = 1; } message FriendListRsp { repeated FriendBase list = 1; }
// //
message Friend_Apply_Req { message FriendApplyReq {
string friendId = 1; //ID string friendId = 1; //ID
} }
message Friend_Apply_Rsp { message FriendApplyRsp {
string userId = 1; //ID string userId = 1; //ID
string friendId = 2; //ID string friendId = 2; //ID
} }
// //
message Friend_Del_Req { message FriendDelReq {
string friendId = 1; //ID string friendId = 1; //ID
} }
message Friend_Del_Rsp { message FriendDelRsp {
string friendId = 1; //ID string friendId = 1; //ID
string userId = 2; //ID string userId = 2; //ID
} }
// //
message Friend_Agree_Req { message FriendAgreeReq {
repeated string friendIds = 1; // repeated string friendIds = 1; //
} }
message Friend_Agree_Rsp { message FriendAgreeRsp {
int32 Num = 1; // int32 Num = 1; //
} }
// //
message Friend_Refuse_Req { message FriendRefuseReq {
repeated string friendIds = 1; // repeated string friendIds = 1; //
} }
message Friend_Refuse_Rsp { message FriendRefuseRsp {
int32 Num = 1; // int32 Num = 1; //
} }
// //
message Friend_ApplyList_Req {} message FriendApplyListReq {}
message Friend_ApplyList_Rsp { repeated FriendBase list = 1; } message FriendApplyListRsp { repeated FriendBase list = 1; }
// //
message Friend_Search_Req { message FriendSearchReq {
string nickName = 1; // string nickName = 1; //
} }
message Friend_Search_Rsp { FriendBase friend = 1; } message FriendSearchRsp { FriendBase friend = 1; }
// //
message Friend_BlackList_Req {} message FriendBlackListReq {}
message Friend_BlackList_Rsp { repeated FriendBase friends = 1; } message FriendBlackListRsp { repeated FriendBase friends = 1; }
// //
message Friend_BlackAdd_Req { string friendId = 1; } message FriendBlackAddReq { string friendId = 1; }
message Friend_BlackAdd_Rsp { message FriendBlackAddRsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message Friend_DelBlack_Req { string friendId = 1; } message FriendDelBlackReq { string friendId = 1; }
message Friend_DelBlack_Rsp { message FriendDelBlackRsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message Friend_Receive_Req { string friendId = 1; } message FriendReceiveReq { string friendId = 1; }
message Friend_Receive_Rsp { message FriendReceiveRsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message Friend_Give_Req { string friendId = 1; } message FriendGiveReq { string friendId = 1; }
message Friend_Give_Rsp { message FriendGiveRsp {
string friendId = 1; string friendId = 1;
string userId = 2; string userId = 2;
} }
// //
message Friend_Total_Req { string friendId = 1; } message FriendTotalReq { string friendId = 1; }
message Friend_Total_Rsp { message FriendTotalRsp {
string friendId = 1; string friendId = 1;
int32 total = 2; // int32 total = 2; //
} }

View File

@ -0,0 +1,38 @@
syntax = "proto3";
option go_package = ".;pb";
package pb;
message SkillData {
int32 skillID = 1;
int32 skillLv = 2;
}
message DBHero {
string id = 1; //@go_tags(`bson:"_id"`) ID
string uid = 2;
int32 heroID = 3; //@go_tags(`bson:"heroID"`) ID
int32 star = 4; //
int32 lv = 5; //
int32 exp = 6; //
int32 juexingLv = 7; //@go_tags(`bson:"juexingLv"`)
int32 captainSkill = 8; //@go_tags(`bson:"captainSkill"`)
repeated SkillData normalSkill = 9; //@go_tags(`bson:"normalSkill"`)
map<int32, int32> property = 10; //
map<int32, int32> addProperty =
11; //@go_tags(`bson:"addProperty"`)
int32 formation = 12; //
int32 cardType =
13; //@go_tags(`bson:"cardType"`) ()
int32 curSkin = 14; //@go_tags(`bson:"curSkin"`) ID
repeated int32 skins = 15; // ID
bool block = 16; //
repeated string equipID = 17; //@go_tags(`bson:"equipID"`) objID
int32 resonateNum = 18; //@go_tags(`bson:"resonateNum"`)
int32 distributionResonate =
19; //@go_tags(`bson:"distributionResonate"`)
map<int32, int32> energy = 20; // @go_tags(`bson:"energy"`)
int32 sameCount = 21; // @go_tags(`bson:"sameCount"`)
int32 suiteId = 22; //@go_tags(`bson:"suiteId"`) Id
int32 suiteExtId = 23; // go_tags(`bson:"suiteExtId"`) Id
bool isOverlying = 24; // go_tags(`bson:"isOverlying"`) true
}

120
src/pb/proto/hero_msg.proto Normal file
View File

@ -0,0 +1,120 @@
syntax = "proto3";
option go_package = ".;pb";
package pb;
import "hero_db.proto";
//
message HeroInfoReq {
string heroId = 1; //ID
}
message HeroInfoRsp { DBHero base = 1; }
//
message HeroListReq {}
message HeroListRsp { repeated DBHero list = 1; }
/// : ()
/// : (使)
/// : ()
message ItemData {
int32 itemId = 2; //Id
int32 amount = 3; //
}
//
message HeroStrengthenUplvReq {
string heroObjID = 1; // ID
string expCardID = 2; // ID
int32 amount = 3; // }
}
//
message HeroStrengthenUplvResp {
DBHero hero = 1; //
}
message CostCardData {
string costCardObj = 1; // ID
int32 amount = 2; //
}
//
message HeroStrengthenUpStarReq {
string heroObjID = 1; // ID
repeated CostCardData hero = 2; // ID
repeated CostCardData heroRace = 3; // ID
}
//
message HeroStrengthenUpStarResp {
DBHero hero = 1; //
}
//
message HeroStrengthenUpSkillReq {
string heroObjID = 1; // ID
string costCardObj = 2; //
}
//
message HeroStrengthenUpSkillResp {
DBHero hero = 1; //
}
//
message HeroResonanceReq {
string heroObjID = 1; // ID
string costObjID = 2; //
int32 amount = 3;//
}
message HeroResonanceResp {
DBHero hero = 1; //
int32 energy = 2; //
DBHero upStarCard = 3; //
}
//
message HeroResonanceResetReq {
string heroObjID = 1; // ID
}
message HeroResonanceResetResp {
DBHero hero = 1; //
int32 energy = 2; //
}
// 使
message HeroResonanceUseEnergyReq {
string heroObjID = 1; // ID
int32 useEnergy = 2; // 使
int32 useType = 3; // 使
}
message HeroResonanceUseEnergyResp {
DBHero hero = 1; //
}
//
message HeroJuexingReq {
string heroObjID = 1; // ID
ItemData costItmes = 2; //
}
//
message HeroJuexingResp {
DBHero hero = 1; //
}
//
message HeroChoukaReq {}
message HeroChoukaResp { repeated DBHero heroes = 1; }
//
message HeroProperty {
string heroId = 1; //ID
map<int32, int32> property = 2; //
map<int32, int32> addProperty = 3; //
}

View File

@ -1,37 +1,37 @@
syntax = "proto3"; syntax = "proto3";
option go_package = ".;pb"; option go_package = ".;pb";
import "pack_db.proto"; import "items_db.proto";
// //
message Pack_Getlist_Req { message ItemsGetlistReq {
int32 IType = 1; // int32 IType = 1; //
} }
// //
message Pack_Getlist_Resp { message ItemsGetlistResp {
repeated DB_UserItemData Grids = 1; // repeated DB_UserItemData Grids = 1; //
} }
//使 //使
message Pack_UseItem_Req { message ItemsUseItemReq {
int32 GridId = 1; //Id int32 GridId = 1; //Id
int32 ItemId = 2; //Id int32 ItemId = 2; //Id
uint32 Amount = 3; //使 uint32 Amount = 3; //使
} }
//使 //使
message Pack_UseItem_Resp { message ItemsUseItemResp {
} }
//sailitem //sailitem
message Pack_SellItem_Req { message ItemsSellItemReq {
int32 GridId = 1; //Id int32 GridId = 1; //Id
int32 ItemId = 2; //Id int32 ItemId = 2; //Id
uint32 Amount = 3; //使 uint32 Amount = 3; //使
} }
// //
message Pack_SellItem_Resp { message ItemsSellItemResp {
} }

View File

@ -11,7 +11,7 @@ message MailAttachment { // 附件
uint32 ItemCount = 2; // uint32 ItemCount = 2; //
} }
message DB_MailData { message DBMailData {
string ObjId = 1; // @go_tags(`bson:"_id"`) ID string ObjId = 1; // @go_tags(`bson:"_id"`) ID
string Uid = 2; string Uid = 2;
string Title = 3; // string Title = 3; //

View File

@ -2,38 +2,38 @@ syntax = "proto3";
option go_package = ".;pb"; option go_package = ".;pb";
import "mail_db.proto"; import "mail_db.proto";
message Mail_GetList_Req { message MailGetListReq {
} }
// //
message Mail_GetList_Resp { message MailGetListResp {
repeated DB_MailData Mails = 1; repeated DBMailData Mails = 1;
} }
// //
message Mail_ReadMail_Req { message MailReadMailReq {
string ObjID = 1; string ObjID = 1;
} }
message Mail_ReadMail_Resp { message MailReadMailResp {
DB_MailData Mail = 1; DBMailData Mail = 1;
} }
// //
message Mail_GetUserMailAttachment_Req { message MailGetUserMailAttachmentReq {
string ObjID = 1; string ObjID = 1;
} }
message Mail_GetUserMailAttachment_Resp { message MailGetUserMailAttachmentResp {
DB_MailData Mail = 1; DBMailData Mail = 1;
} }
// //
message Mail_DelMail_Req { message MailDelMailReq {
string ObjID = 1; string ObjID = 1;
} }
message Mail_DelMail_Resp { message MailDelMailResp {
repeated DB_MailData Mail = 1; repeated DBMailData Mail = 1;
} }

View File

@ -3,9 +3,10 @@ option go_package = ".;pb";
import "errorcode.proto"; import "errorcode.proto";
// //
message ErrorNotify { message NotifyErrorNotifyPush {
string ReqMainType =1; // :user user的模块 string ReqMainType = 1; // :user user的模块
string ReqSubType = 2; // :login user的模块中 api_login string ReqSubType = 2; // :login user的模块中
// api_login
ErrorCode Code = 3; // errorcode.proto ErrorCode Code = 3; // errorcode.proto
string Message = 4; // string Message = 4; //
string Data = 6; // string Data = 6; //

View File

@ -1,14 +1,14 @@
syntax = "proto3"; syntax = "proto3";
option go_package = ".;pb"; option go_package = ".;pb";
message Cache_UserData { message CacheUser {
string uid = 1; string uid = 1;
string SessionId = 2; string SessionId = 2;
string GatewayServiceId = 3; string GatewayServiceId = 3;
// DB_UserData UserData = 4; //@go_tags(`json:",inline"`) // DB_UserData UserData = 4; //@go_tags(`json:",inline"`)
} }
message DB_UserData { message DBUser {
string id = 1; //@go_tags(`bson:"_id"`) ID string id = 1; //@go_tags(`bson:"_id"`) ID
string uid = 2; //@go_tags(`bson:"uid"`) ID string uid = 2; //@go_tags(`bson:"uid"`) ID
string uuid = 3; //@go_tags(`bson:"uuid"`) uuid string uuid = 3; //@go_tags(`bson:"uuid"`) uuid
@ -21,4 +21,6 @@ message DB_UserData {
int64 logintime = 10; //@go_tags(`bson:"logintime"`) int64 logintime = 10; //@go_tags(`bson:"logintime"`)
int32 friendPoint = 11; //@go_tags(`bson:"friendPoint"`) int32 friendPoint = 11; //@go_tags(`bson:"friendPoint"`)
int32 avatar = 12; //@go_tags(`bson:"avatar"`) int32 avatar = 12; //@go_tags(`bson:"avatar"`)
int32 gold = 13; //@go_tags(`bson:"gold"`)
int32 exp = 14; //@go_tags(`bson:"exp"`)
} }

View File

@ -9,7 +9,7 @@ message UserLoginReq {
int32 sid = 2; // int32 sid = 2; //
} }
message UserLoginResp { DB_UserData data = 1; } message UserLoginResp { DBUser data = 1; }
message UserRegisterReq { message UserRegisterReq {
string account = 1; string account = 1;
@ -21,7 +21,7 @@ message UserRegisterRsp {
string account = 2; string account = 2;
} }
message UserLoadRsp { Cache_UserData data = 1; } message UserLoadRsp { CacheUser data = 1; }
// //
message UserCreateReq { message UserCreateReq {

View File

@ -18,7 +18,7 @@ var socket = {
hearbeat_interval: 5000, hearbeat_interval: 5000,
// 是否自动重连 // 是否自动重连
is_reonnect: true, is_reonnect: false,
// 重连次数 // 重连次数
reconnect_count: 3, reconnect_count: 3,
// 已发起重连次数 // 已发起重连次数
@ -27,7 +27,10 @@ var socket = {
reconnect_timer: null, reconnect_timer: null,
// 重连频率 // 重连频率
reconnect_interval: 3000, reconnect_interval: 3000,
// 消息监听
receivelisten: null,
// 关闭监听
closelisten: null,
/** /**
* 初始化连接 * 初始化连接
*/ */
@ -45,27 +48,10 @@ var socket = {
* @param {*} callback 发送后的自定义回调函数 * @param {*} callback 发送后的自定义回调函数
*/ */
send: (data, callback = null) => { send: (data, callback = null) => {
// 开启状态直接发送 socket.websock.send(data)
if (socket.websock.readyState === socket.websock.OPEN) {
socket.websock.send(JSON.stringify(data))
if (callback) { if (callback) {
callback() callback()
} }
// 正在开启状态则等待1s后重新调用
} else if (socket.websock.readyState === socket.websock.CONNECTING) {
setTimeout(function () {
socket.send(data, callback)
}, 1000)
// 未开启则等待1s后重新调用
} else {
socket.init()
setTimeout(function () {
socket.send(data, callback)
}, 1000)
}
}, },
/** /**
@ -180,8 +166,12 @@ var socket = {
} }
socket.websock = new WebSocket(socket.ws_url) socket.websock = new WebSocket(socket.ws_url)
socket.websock.onmessage = function (e) { socket.websock.onmessage = function (e) {
if (socket.receivelisten != null) {
socket.receivelisten(e)
} else {
socket.receive(e) socket.receive(e)
} }
}
// 关闭连接 // 关闭连接
socket.websock.onclose = function (e) { socket.websock.onclose = function (e) {
console.log('连接已断开') console.log('连接已断开')
@ -202,6 +192,10 @@ var socket = {
socket.reconnect_current++ socket.reconnect_current++
return socket.connect(resolve, reject) return socket.connect(resolve, reject)
}, socket.reconnect_interval) }, socket.reconnect_interval)
} else {
if (socket.closelisten != null)
socket.closelisten()
return reject("连接失败")
} }
} }
@ -210,9 +204,9 @@ var socket = {
console.log('连接成功') console.log('连接成功')
socket.reconnect_current = 0 socket.reconnect_current = 0
socket.socket_open = true socket.socket_open = true
socket.is_reonnect = true // socket.is_reonnect = true
// 开启心跳 // 开启心跳
socket.heartbeat() // socket.heartbeat()
resolve(socket.websock) resolve(socket.websock)
} }
// 连接发生错误 // 连接发生错误
@ -221,7 +215,5 @@ var socket = {
console.log('WebSocket连接发生错误') console.log('WebSocket连接发生错误')
// reject("WebSocket连接发生错误") // reject("WebSocket连接发生错误")
} }
}, },
} }

View File

@ -27,17 +27,105 @@
</v-row> </v-row>
<v-divider inset></v-divider> <v-divider inset></v-divider>
<v-row class="mt-5"> <v-row class="mt-5">
<v-col cols="4"> <v-col cols="2">
<v-select :items="proto_models" <v-select v-model="mainSelect"
label="选择测试模块"></v-select> :items="proto_models"
item-title="mainType"
item-value="subs"
label="mainType"
:disabled="!isconnect"
@update:modelValue="mainSelectUpdate"
single-line
return-object></v-select>
</v-col> </v-col>
<v-col cols="4"> <v-col cols="2">
<v-select :items="proto_models" <v-select v-model="subSelect"
label="选择子协议"></v-select> :items="mainSelect.subs"
item-title="subType"
item-value="reqproto"
label="subType"
:disabled="!isconnect || mainSelect.disabled"
@update:modelValue="subSelectUpdate"
single-line
return-object></v-select>
</v-col>
</v-row>
<v-divider inset></v-divider>
<v-row v-if="reqproto.length > 0"
class="mt-5">
<v-col v-for="item in reqproto"
:key="item.FieldName"
cols="4">
<v-text-field color="tertiary"
v-model="item.FieldValue"
:label="item.FieldName"
:type="item.FieldType"
:hint="item.FieldType"
:disabled="!isconnect"
outlined
clearable></v-text-field>
</v-col>
</v-row>
<v-row class="mt-5">
<v-col cols="3">
<v-btn flat
class="text-capitalize"
:disabled="subSelect == null"
@click="reqprotohandle"
color="secondary">
request
</v-btn>
</v-col> </v-col>
</v-row> </v-row>
</v-card-text> </v-card-text>
</v-card> </v-card>
<v-card class="mt-12">
<v-card-title>
<v-row justify="space-between">
<v-col>输出</v-col>
<v-col cols="auto">
<v-btn flat
prepend-icon="mdi-broom"
@click="logs=[]"
color="secondary">
Clear
</v-btn>
</v-col>
</v-row>
</v-card-title>
<v-divider></v-divider>
<v-responsive class="overflow-y-auto"
height="500">
<v-lazy :options="{threshold: .5}"
min-height="200"
transition="fade-transition">
<v-list>
<v-list-item v-for="log in logs"
:key="log">
<v-alert :type="log.type"
variant="outlined"
:title="log.title">
<template v-if="log.data"
v-slot:append>
<v-list-item-avatar end>
<v-btn variant="text"
size="x-large"
@click="log.isshow = !log.isshow"
:icon="log.isshow ? 'mdi-chevron-left':'mdi-chevron-down'"></v-btn>
</v-list-item-avatar>
</template>
<div v-if="log.data"
v-show="log.isshow">
<v-divider></v-divider>
<pre>{{log.data}}</pre>
</div>
</v-alert>
</v-list-item>
</v-list>
</v-lazy>
</v-responsive>
</v-card>
<v-snackbar v-model="error"> <v-snackbar v-model="error">
{{ error_message }} {{ error_message }}
<template v-slot:actions> <template v-slot:actions>
@ -52,6 +140,8 @@
</template> </template>
<script> <script>
import { Base64 } from 'js-base64'
import md5 from 'js-md5'
import { reactive } from 'vue' import { reactive } from 'vue'
import proto from '@/pb/proto' import proto from '@/pb/proto'
import { socket } from '@/utils/socket' import { socket } from '@/utils/socket'
@ -67,24 +157,106 @@ export default defineComponent({
connecting: false, connecting: false,
error: false, error: false,
error_message: '', error_message: '',
protodata: {}, proto_models: null,
proto_models: [], mainSelect: { protoName: '', mainType: 'User', subs: [] },
subSelect: null,
reqproto: [],
reqloading: false,
islogin: false,
account: '',
serverId: 0,
logs: [],
isshow: true,
showdata: { name: 'liwei1dao', aog: 123 },
} }
}, },
computed: {},
setup() { setup() {
const protodata = reactive([]) const proto_models = reactive([
const proto_models = reactive([]) { mainType: 'notify', disabled: true, subs: [] },
{ mainType: 'user', subs: [] },
{ mainType: 'items', subs: [] },
{ mainType: 'mail', subs: [] },
{ mainType: 'friend', subs: [] },
{ mainType: 'equipment', subs: [] },
{ mainType: 'hero', subs: [] },
])
for (const v of Object.keys(proto)) { for (const v of Object.keys(proto)) {
let arr = v.split('_') for (const v1 of proto_models) {
if (arr.length == 3) { let protoName = v.toLowerCase()
console.log(v) // console.log('protoName', protoName)
var value = proto[v] //
protodata[arr[0]] = value let index = protoName.indexOf(v1.mainType)
console.log(value) if (index == 0) {
proto_models.push(arr[0]) let reqindex = protoName.indexOf('req')
let respindex = protoName.indexOf('resp')
let pushindex = protoName.indexOf('push')
if (reqindex != -1) {
let sub = protoName.substring(index + v1.mainType.length, reqindex)
let iskeep = false
for (const v2 of v1.subs) {
if (v2.subType == sub) {
v2.reqproto = proto[v]
iskeep = true
break
} }
} }
return { protodata, proto_models } if (!iskeep) {
v1.subs.push({
reqName: v,
mainType: v1.mainType,
subType: sub,
reqproto: proto[v],
})
console.log(sub + 'Req')
}
}
if (respindex != -1) {
let sub = protoName.substring(index + v1.mainType.length, respindex)
let iskeep = false
for (const v2 of v1.subs) {
if (v2.subType == sub) {
v2.respName = v
v2.respproto = proto[v]
iskeep = true
break
}
}
if (!iskeep) {
v1.subs.push({
respName: v,
mainType: v1.mainType,
subType: sub,
respproto: proto[v],
})
console.log(sub + 'Resp')
}
}
if (pushindex != -1) {
let sub = protoName.substring(index + v1.mainType.length, pushindex)
let iskeep = false
for (const v2 of v1.subs) {
if (v2.subType == sub) {
v2.pushName = v
v2.pushproto = proto[v]
iskeep = true
break
}
}
if (!iskeep) {
v1.subs.push({
pushName: v,
mainType: v1.mainType,
subType: sub,
pushproto: proto[v],
})
console.log(sub + 'Resp')
}
}
}
}
}
return { proto_models }
}, },
onBeforeUnmount() { onBeforeUnmount() {
// //
@ -94,6 +266,8 @@ export default defineComponent({
connect() { connect() {
// //
this.connecting = true this.connecting = true
socket.receivelisten = this.receivelisten
socket socket
.init(this.ws_url) .init(this.ws_url)
.then((value) => { .then((value) => {
@ -101,19 +275,180 @@ export default defineComponent({
this.error_message = '' this.error_message = ''
this.isconnect = true this.isconnect = true
this.connecting = false this.connecting = false
this.pushlog('success', `连接创建成功`)
socket.closelisten = this.closelisten
}) })
.catch((error) => { .catch((error) => {
this.error = true this.error = true
this.error_message = error this.error_message = error
this.isconnect = false this.isconnect = false
this.connecting = false this.connecting = false
this.subSelect = null
this.reqproto = []
this.pushlog('error', `连接创建失败:${this.ws_url}`)
}) })
}, },
disconnect() { disconnect() {
socket.close() socket.close()
this.isconnect = false this.isconnect = false
this.subSelect = null
this.reqproto = []
},
mainSelectUpdate(v) {
console.log(v)
this.subSelect = null
this.reqproto = []
},
subSelectUpdate(v) {
console.log(v)
this.reqproto = []
let keys = Object.keys(this.subSelect.reqproto.fields)
for (const v of keys) {
let ftype = this.subSelect.reqproto.fields[v].type
let fvalue = null
switch (this.subSelect.reqproto.fields[v].type) {
case 'int32':
case 'int64':
case 'uint32':
case 'uint64':
case 'float32':
case 'float64':
ftype = 'number'
fvalue = 0
break
default:
ftype = 'text'
fvalue = ''
}
this.reqproto.push({
FieldName: v,
FieldType: ftype,
FieldValue: fvalue,
})
}
console.log(this.reqproto)
},
closelisten() {
this.isconnect = false
this.subSelect = null
this.reqproto = []
console.log('closelisten!')
this.pushlog('error', `连接断开${this.ws_url}`)
},
//
receivelisten(msg) {
// console.log('', msg.data.arrayBuffer())
msg.data
.arrayBuffer()
.then((buf) => new Uint8Array(buf))
.then((bytes) => {
console.log('bytes', bytes)
let message = proto.lookup('UserMessage').decode(bytes)
console.log('接收到消息 message', message)
let mainType = message.MainType
let subType = message.SubType
let iskeep = false
for (const v of this.proto_models) {
if (v.mainType == mainType) {
for (const v1 of v.subs) {
if (subType == v1.subType) {
console.log('接收到消息 v1', v1)
//
iskeep = true
let protoobj = null
let messageobj = null
if (v1.respName) {
console.log('接收到消息 respName', v1.respName)
protoobj = proto
.lookup(v1.respName)
.decode(message.data.value)
messageobj = proto.lookup(v1.respName).toObject(protoobj)
// console.log(' protoobj', protoobj)
} else {
console.log('接收到消息 pushName', v1.pushName)
protoobj = proto
.lookup(v1.pushName)
.decode(message.data.value)
messageobj = proto.lookup(v1.pushName).toObject(protoobj)
}
this.pushlog(
'success',
`收到回应消息: ${mainType}-${subType}-resp`,
messageobj
)
}
}
}
if (iskeep) {
break
}
}
if (!iskeep) {
this.pushlog(
'error',
`接收消息错误 ${mainType}-${subType}`,
'未找到指定消息对象'
)
}
})
.catch((error) => {
console.log('接收到消息异常', error)
this.pushlog('error', '接收消息异常', { msg: msg, e: e })
})
},
//
reqprotohandle() {
console.log('protoName:', this.subSelect.reqName)
let protoobj = proto.lookup(this.subSelect.reqName)
for (const v of this.reqproto) {
protoobj[v.FieldName] = v.FieldValue
}
let message = proto.lookup('UserMessage')
let any = proto.lookup('google.protobuf.Any')
message.MainType = this.subSelect.mainType
message.SubType = this.subSelect.subType
message.data = any.create({
type_url: `type.googleapis.com/${this.subSelect.reqName}`,
value: proto.lookup(this.subSelect.reqName).encode(protoobj).finish(), // Or as packed buffer
})
if (this.subSelect.reqName == 'UserLoginReq') {
//
message.sec = this.buildsecStr(protoobj.account, protoobj.sid)
} else {
message.sec = this.buildsecStr()
}
console.log('message:', message)
let buffer = proto.lookup('UserMessage').encode(message).finish()
console.log('req buff:', buffer)
socket.send(buffer)
this.pushlog(
'success',
`发送请求消息: ${message.MainType}-${message.SubType}-req`,
proto.lookup(this.subSelect.reqName).toObject(protoobj)
)
},
buildsecStr(_account, _serverId) {
_account = _account ? _account : this.account
_serverId = _serverId ? _serverId : this.serverId
let jsonStr = JSON.stringify({
account: _account,
serverId: _serverId,
timestamp: Date.parse(new Date()) / 1000,
})
let baseStr = Base64.encode(jsonStr)
let clientMd5key = md5(baseStr)
console.log('clientMd5key:', clientMd5key)
return `CE:${clientMd5key}${baseStr}`
},
pushlog(_type, _title, _data) {
this.logs.push({
type: _type,
title: _title,
data: _data,
isshow: false,
})
}, },
loginreq() {},
}, },
}) })
</script> </script>