Skip to content

Commit d30e180

Browse files
committed
update data
1 parent f4e5b4d commit d30e180

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package main
22

33
import (
4-
_ "Proto"
4+
"LollipopGo/LollipopGo/util"
5+
"Proto"
56
"Proto/Proto2"
67
"fmt"
78
)
@@ -39,6 +40,29 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
3940
// 登录游戏协议
4041
func (this *NetDataConn) LoginGameSnake(ProtocolData map[string]interface{}) {
4142
// 数据链接信息需要保存
43+
if ProtocolData["Login_Name"] == nil ||
44+
ProtocolData["Login_PW"] == nil {
45+
panic("玩家登录协议不存在, 字段为空!")
46+
return
47+
}
48+
StrLogin_Name := ProtocolData["Login_Name"].(string)
49+
// StrLogin_PW := ProtocolData["Login_PW"].(string)
50+
// 数据库验证
51+
// 1 获取到UID 信息
52+
// 服务器-->客户端
53+
// 2 获取玩家的信息 --> player data
54+
// 3 保存到内存中的数据
55+
data := &Proto2.Net_HeartBeat{
56+
Protocol: Proto.GameNet_Proto,
57+
Protocol2: Proto2.Net_HeartBeatProto2,
58+
OpenID: "",
59+
}
60+
// 发送数据给客户端了
61+
this.PlayerSendMessage(data)
62+
// 玩家信息保存到 内存中
63+
// MD5信息操作
64+
strRoom := "UID" // 玩家房间的ID信息:信息的组成主要是 游戏ID+房间ID信息 确定数据是唯一的
65+
this.MapSafe.Put(StrLogin_Name+"|"+util.MD5_LollipopGO(strRoom)+"|connect", "")
4266

4367
return
4468
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func initMatch(conn *websocket.Conn) {
2222
data := &Proto2.C2S_PlayerEntryGame{
2323
Protocol: Proto.G_Snake_Proto, // 游戏主要协议
2424
Protocol2: Proto2.C2S_PlayerEntryGameProto2,
25-
Code: util.CreateTime(), // 随机生产的数据,时间戳
25+
Code: util.UTCTime_LollipopGO(), // 随机生产的数据,时间戳
2626
}
2727
// fmt.Println(data)
2828
// 2 发送数据到服务器

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
package send
1+
package main
22

33
import (
4-
"fmt"
4+
"Proto"
5+
"Proto/Proto2"
6+
_ "fmt"
7+
8+
"code.google.com/p/go.net/websocket"
59
)
610

711
// 发送坐标数据 --==--
@@ -12,7 +16,7 @@ func Send_XYZ_Data(conn *websocket.Conn, strOpenID string, strRoomID string, OP_
1216
Protocol: Proto.G_Snake_Proto, // 游戏主要协议
1317
Protocol2: Proto2.C2S_PlayerMoveProto2,
1418
OpenID: strOpenID, // 随机生产的数据,时间戳
15-
RoomID: strRoomID,
19+
RoomID: 1,
1620
OP_ULRDP: OP_ULRDP,
1721
}
1822
// 2 发送数据到服务器

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package util
22

33
import (
4+
"crypto/md5"
5+
"encoding/hex"
46
"strconv"
57
"time"
68
)
79

10+
//------------------------------------------------------------------------------
11+
812
// package main
913

1014
// import (
@@ -35,7 +39,34 @@ import (
3539
// 1498017149
3640

3741
// 生成时间戳的函数
38-
func CreateTime() string {
42+
func UTCTime_LollipopGO() string {
3943
t := time.Now()
4044
return strconv.FormatInt(t.UTC().UnixNano(), 10)
4145
}
46+
47+
//------------------------------------------------------------------------------
48+
// package main
49+
50+
// import (
51+
// "crypto/md5"
52+
// "encoding/hex"
53+
// "fmt"
54+
// )
55+
56+
// func main() {
57+
// h := md5.New()
58+
// h.Write([]byte("123456")) // 需要加密的字符串为 123456
59+
// cipherStr := h.Sum(nil)
60+
// fmt.Println(cipherStr)
61+
// fmt.Printf("%s\n", hex.EncodeToString(cipherStr)) // 输出加密结果
62+
// }
63+
64+
// MD5 实现 :主要是针对 字符串的加密
65+
func MD5_LollipopGO(data string) string {
66+
h := md5.New()
67+
h.Write([]byte(data))
68+
cipherStr := h.Sum(nil)
69+
return hex.EncodeToString(cipherStr)
70+
}
71+
72+
//------------------------------------------------------------------------------

第一季 从零开始写游戏服务器 第二期/最新课节--课程代码/vender/src/Proto/Proto2/Proto2Snake.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const (
1111
C2S_PlayerMoveProto2 // C2S_PlayerMoveProto2 == 5 移动操作
1212
S2S_PlayerMoveProto2 // S2S_PlayerMoveProto2 == 6
1313

14-
S2S_PlayerMoveProto2 // S2S_PlayerMoveProto2 == 7 玩家死亡操作
14+
//S2S_PlayerMoveProto2 // S2S_PlayerMoveProto2 == 7 玩家死亡操作
15+
1516
)
1617

1718
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)