Skip to content

Commit e87ce63

Browse files
committed
update data
1 parent 57fe8c4 commit e87ce63

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ import (
1111

1212
func IndexHandler(w http.ResponseWriter, r *http.Request) {
1313
fmt.Fprintln(w, "hello world")
14-
// 需要处理 get请求等
14+
// 需要处理 get 请求等
15+
// 1 base64 操作 ---
1516
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,26 @@ func (this *NetDataConn) HandleCltProtocol2Snake(protocol2 interface{}, Protocol
3232

3333
// 玩家 进入游戏的协议
3434
func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
35+
if ProtocolData["Code"] == nil ||
36+
ProtocolData["Code"] == nil {
37+
panic("玩家进入游戏数据错误, 字段为空!")
38+
return
39+
}
40+
StrLogin_Name := ProtocolData["Code"].(string)
41+
Icode := ProtocolData["Icode"].(float64)
3542
// 进入游戏 进行匹配
3643
fmt.Println("玩家进行匹配!!!")
3744
// 1 匹配算法 --》匹配在线玩家的
45+
// 2 保存数据 --> chnnel 环境操作
46+
Chan_match <- Icode
47+
// 3 返回数据
3848

39-
// 2 返回数据
49+
// 4 发送数据 --> 返回数据操作
4050
data := &Proto2.S2S_PlayerEntryGame{
4151
Protocol: Proto.G_Snake_Proto,
4252
Protocol2: Proto2.S2S_PlayerEntryGameProto2,
4353
RoomID: 1,
44-
MapPlayer: nil,
54+
MapPlayer: nil, // 玩家的名字
4555
}
4656
// 发送数据给客户端了
4757
this.PlayerSendMessage(data)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var M *concurrent.ConcurrentMap // 并发安全的
2020
var addr = flag.String("addr", "127.0.0.1:8888", "http service address")
2121
var WS *websocket.Conn
2222
var icount, icounttmp int
23+
var Chan_match chan int
24+
var Chan_Number int = 100
2325

2426
// 游戏服务器的初始化
2527
func init() {
@@ -28,6 +30,7 @@ func init() {
2830
G_PlayerNet = make(map[string]int)
2931
G_PlayerNetSys = make(map[string]int)
3032
G_Net_Count = make(map[string]int)
33+
Chan_match = make(chan int, Chan_Number)
3134
// 并发安全的初始化
3235
M = concurrent.NewConcurrentMap()
3336
// go G_timer()

0 commit comments

Comments
 (0)