登录代码提交

This commit is contained in:
tangping
2025-01-15 17:36:12 +08:00
parent 8c40855c4e
commit 22ac6c1fed
39 changed files with 2551 additions and 189 deletions

View File

@@ -0,0 +1,63 @@
package model
// 返回结果状态
type ResultStatus struct {
// 状态值(成功是0非成功以负数来表示)
Code int
// 状态信息
Message string
}
func newResultStatus(code int, message string) *ResultStatus {
return &ResultStatus{
Code: code,
Message: message,
}
}
// 定义所有的响应结果的状态枚举值
var (
Success = newResultStatus(0, "成功")
DataError = newResultStatus(-1, "数据错误")
DBError = newResultStatus(-2, "数据库错误")
MethodNotDefined = newResultStatus(-3, "方法未定义")
ParamIsEmpty = newResultStatus(-4, "参数为空")
ParamNotMatch = newResultStatus(-5, "参数不匹配")
ParamTypeError = newResultStatus(-6, "参数类型错误")
OnlySupportPOST = newResultStatus(-7, "只支持POST")
APINotDefined = newResultStatus(-8, "API未定义")
APIParamError = newResultStatus(-9, "API参数错误")
InvalidIP = newResultStatus(-10, "IP无效")
PlayerNotExists = newResultStatus(-11, "玩家不存在")
NoAvailableServer = newResultStatus(-12, "没有可用的服务器")
ClientDataError = newResultStatus(-13, "客户端数据错误")
TokenInvalid = newResultStatus(-14, "令牌无效")
ChannelNotDefined = newResultStatus(-15, "聊天频道未定义")
NoTargetMethod = newResultStatus(-16, "找不到目标方法")
ParamInValid = newResultStatus(-17, "参数无效")
NoLogin = newResultStatus(-18, "尚未登陆")
NotInUnion = newResultStatus(-19, "不在公会中")
NotInShimen = newResultStatus(-20, "不在师门中")
NotFoundTarget = newResultStatus(-21, "未找到目标玩家")
PlayerNotExist = newResultStatus(-22, "玩家不存在")
ServerGroupNotExist = newResultStatus(-23, "服务器组不存在")
NotInTeam = newResultStatus(-24, "不在队伍中")
LoginOnAnotherDevice = newResultStatus(-25, "在另一台设备上登录")
CantSendMessageToSelf = newResultStatus(-26, "不能给自己发消息")
ResourceNotEnough = newResultStatus(-27, "资源不足")
NetworkError = newResultStatus(-28, "网络错误")
ContainForbiddenWord = newResultStatus(-29, "含有屏蔽词语")
SendMessageTooFast = newResultStatus(-30, "发送消息太快")
LvIsNotEnough = newResultStatus(-31, "等级不足,系统未开放")
RepeatTooMuch = newResultStatus(-32, "重复次数太多")
CantCrossServerTalk = newResultStatus(-33, "不能跨服私聊")
InSilent = newResultStatus(-34, "您的账号已被禁言,请联系客服反馈。")
NotInCountry = newResultStatus(-35, "不在国家中")
CantSendMessageToGM = newResultStatus(-36, "当前GM对话已结束如有疑问请联系客服QQ咨询")
DisconnectStatus = newResultStatus(-37, "DisconnectStatus")
LanguageToTextError = newResultStatus(-38, "语音转换失败!")
VoiceCloudNotDefined = newResultStatus(-15, "语音识别云商不存在")
ContainForbiddenWordForQCGreen = newResultStatus(-39, "内容含有屏蔽词语")
ContainForbiddenWordForZSYDun = newResultStatus(-59, "内容中含有屏蔽词语")
)

View File

@@ -0,0 +1,29 @@
package model
// 请求对象
type ServerRequestObject struct {
// 请求的唯一标识是需要通过截取请求数据前4位得到并进行手动赋值的暂时未使用
RequestId int64
// 请求的模块名称
ModuleName string
// 请求的方法名称
MethodName string
// 请求的参数数组
Parameters []interface{}
// 客户端发送请求的时间
SendTime int64
ReachTime int64
InQueueTime int64
HandleStartTime int64
HandleEndTime int64
ReturnTime int64
}

View File

@@ -0,0 +1,89 @@
package model
import (
"strconv"
"time"
)
// 服务器响应对象
type ServerResponseData struct {
// Id
Id int
// 聊天频道
Channel string
// 聊天消息
Message string
// 语音信息
Voice string
// 语音文字
VoiceText string
// 发送人
FromPlayer string
FromPlayerId string
// 接收人
ToPlayer string `json:"ToPlayer,omitempty"`
ToPlayerId string `json:"ToPlayerId,omitempty"`
// 创建的时间戳
TimeStamp int64
//是否是离线消息
IfOffline bool
//是否已读消息
IfRead bool
}
// 创建新的服务器响应对象
func NewServerResponseData(id int, channel, message, voice, voiceText string, from, to *Player, ifOffline, ifRead int32) *ServerResponseData {
var fromPlayer, toPlayer string
var fromPlayerId, toPlayerId int64
if from != nil {
fromPlayerId = from.Id
fromPlayer = from.String()
}
if to != nil {
toPlayerId = to.Id
toPlayer = to.String()
}
return &ServerResponseData{
Id: id,
Channel: channel,
Message: message,
Voice: voice,
VoiceText: voiceText,
FromPlayer: fromPlayer,
FromPlayerId: strconv.FormatInt(fromPlayerId, 10),
ToPlayer: toPlayer,
ToPlayerId: strconv.FormatInt(toPlayerId, 10),
TimeStamp: time.Now().Unix(),
IfOffline: ifOffline == 1,
IfRead: ifRead == 1,
}
}
// 从其它类型转化为服务器响应对象
func ConvertToServerResponseData(id int, channel, message, voice, voiceText, fromPlayer string, fromPlayerId int64, toPlayer string, toPlayerId int64, timeStamp int64, ifOffline, ifRead bool) *ServerResponseData {
return &ServerResponseData{
Id: id,
Channel: channel,
Message: message,
Voice: voice,
VoiceText: voiceText,
FromPlayer: fromPlayer,
FromPlayerId: strconv.FormatInt(fromPlayerId, 10),
ToPlayer: toPlayer,
ToPlayerId: strconv.FormatInt(toPlayerId, 10),
TimeStamp: timeStamp,
IfOffline: ifOffline,
IfRead: ifRead,
}
}

View File

@@ -0,0 +1,80 @@
package model
import (
"compress/zlib"
"encoding/json"
"goutil/zlibUtil"
)
// ChatServer的响应对象
type ServerResponseObject struct {
// 响应结果的状态值
*ResultStatus
// 响应结果的数据
Data interface{} `json:"Data,omitempty"`
// 响应结果对应的请求的方法名称
MethodName string
// 压缩后的字节
DataByte []byte `json:"-"`
}
func (this *ServerResponseObject) SetResultStatus(rs *ResultStatus) *ServerResponseObject {
this.ResultStatus = rs
return this
}
func (this *ServerResponseObject) SetData(data interface{}) *ServerResponseObject {
this.Data = data
return this
}
func (this *ServerResponseObject) SetMethodName(methodName string) *ServerResponseObject {
this.MethodName = methodName
return this
}
func (this *ServerResponseObject) IsDisconnect() bool {
return this.ResultStatus.Code == DisconnectStatus.Code
}
// Compress
//
// @Description: 压缩数据
// parameter:
// receiver this
// ifCompress
// return:
func (this *ServerResponseObject) Compress(ifCompress bool) {
// 序列化发送的数据
contentObj, _ := json.Marshal(this)
// 进行zlib压缩
if ifCompress {
contentObj, _ = zlibUtil.Compress(contentObj, zlib.DefaultCompression)
}
//赋值
this.DataByte = contentObj
}
func NewServerResponseObject() *ServerResponseObject {
return &ServerResponseObject{
ResultStatus: Success,
Data: nil,
MethodName: "",
}
}
func NewDisconnectServerResponseObject() *ServerResponseObject {
return &ServerResponseObject{
ResultStatus: DisconnectStatus,
Data: nil,
MethodName: "",
}
}