Skip to content

Commit e469ad1

Browse files
committed
update data
1 parent 6b9b6ae commit e469ad1

File tree

2 files changed

+6
-15
lines changed
  • 第一季 从零开始写游戏服务器 第二期/最新课节--课程代码/class3/src/classcode

2 files changed

+6
-15
lines changed

第一季 从零开始写游戏服务器 第二期/最新课节--课程代码/class3/src/classcode/NetData.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,21 @@ func (r *Requestbody) Json2map() (s map[string]interface{}, err error) {
3636
return result, nil
3737
}
3838

39-
// 结构体的方法 - 接受者是指针类型的
4039
func (this *NetDataConn) PullFromClient() {
41-
// 网络层处理 数据
42-
// 1 针对服务器而言 一直等待消息的
43-
// for (){}
4440
for {
4541

4642
var content string
4743
if err := websocket.Message.Receive(this.Connection, &content); err != nil {
4844
break
4945
}
50-
if len(content) == 0 {
46+
if len(content) == 0 || len(content) >= 4096 {
5147
break
5248
}
53-
// go 并发编程使用
5449
go this.SyncMeassgeFun(content)
5550
}
56-
return
5751
}
5852

5953
func (this *NetDataConn) SyncMeassgeFun(content string) {
60-
// 1 字符串---》 其他格式 必须高效 (大量并发情况下 依然不影响性能,游戏服务器 计算密集型的)
61-
// glog.Info(content)
62-
// 2 已经通过第1步转化成我们所要的格式了,实现格式的处理函数:主协议、子协议、struct
63-
// 3 处理函数实现
6454
var r Requestbody
6555
r.req = content
6656

@@ -70,7 +60,6 @@ func (this *NetDataConn) SyncMeassgeFun(content string) {
7060
} else {
7161
glog.Error("解析失败:", err.Error())
7262
}
73-
7463
}
7564

7665
func typeof(v interface{}) string {

第一季 从零开始写游戏服务器 第二期/最新课节--课程代码/class3/src/classcode/NetSnakeClt.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ func (this *NetDataConn) LoginGameSnake(ProtocolData map[string]interface{}) {
5252
// 服务器-->客户端
5353
// 2 获取玩家的信息 --> player data
5454
// 3 保存到内存中的数据
55-
data := &Proto2.Net_HeartBeat{
55+
data := &Proto2.S2S_PlayerLoginS{
5656
Protocol: Proto.GameNet_Proto,
57-
Protocol2: Proto2.Net_HeartBeatProto2,
58-
OpenID: "",
57+
Protocol2: Proto2.S2S_PlayerLoginSProto2,
58+
Token: "123456789",
5959
}
6060
// 发送数据给客户端了
6161
this.PlayerSendMessage(data)
6262
// 玩家信息保存到 内存中
6363
// MD5信息操作
6464
strRoom := "UID" // 玩家房间的ID信息:信息的组成主要是 游戏ID+房间ID信息 确定数据是唯一的
65+
// 数据保存操作
66+
// --> 操作的
6567
this.MapSafe.Put(StrLogin_Name+"|"+util.MD5_LollipopGO(strRoom)+"|connect", "")
6668

6769
return

0 commit comments

Comments
 (0)