File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed
第一季 从零开始写游戏服务器 第二期/最新课节--课程代码/class3/src/classcode Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 4
4
"encoding/json"
5
5
"fmt"
6
6
7
+ "Proto"
8
+ "Proto/Proto2"
9
+
7
10
"code.google.com/p/go.net/websocket"
8
11
)
9
12
@@ -43,6 +46,7 @@ func PlayerSendToServer(conn *websocket.Conn, data interface{}) {
43
46
// 群发广播函数:同一个房间
44
47
func PlayerSendBroadcastToRoomPlayer (iroomID int ) {
45
48
49
+ // 处理数据操纵
46
50
// -------------------------------------------------------------------------
47
51
for itr := M .Iterator (); itr .HasNext (); {
48
52
k , v , _ := itr .Next ()
@@ -51,26 +55,23 @@ func PlayerSendBroadcastToRoomPlayer(iroomID int) {
51
55
if len (strsplit ) < 2 {
52
56
continue
53
57
}
54
- // 进行数据的查询类型
55
- switch v .(interface {}).(type ) {
56
- case * NetDataConn :
57
- {
58
- // 判断 链接是不是 connect
59
- // 数据 处理操作
60
- if "" == "connect" {
58
+
59
+ if strsplit [2 ] == "room" {
60
+ // 进行数据的查询类型
61
+ switch v .(interface {}).(type ) {
62
+ case * NetDataConn :
63
+ { // 发送数据操作
61
64
data := & Proto2.Net_Kicking_Player {
62
65
Protocol : Proto .GameNet_Proto ,
63
66
Protocol2 : Proto2 .Net_Kicking_PlayerProto2 ,
64
67
ErrorCode : 10001 ,
65
68
}
66
- // 发送数据
67
69
v .(interface {}).(* NetDataConn ).PlayerSendMessage (data )
68
70
}
69
71
}
70
72
}
71
73
}
72
74
}
73
-
74
75
// -------------------------------------------------------------------------
75
76
return
76
77
}
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
37
37
panic ("玩家进入游戏数据错误, 字段为空!" )
38
38
return
39
39
}
40
- //StrLogin_Name := ProtocolData["Code"].(string)
40
+ strCode := ProtocolData ["Code" ].(string )
41
41
Icode := ProtocolData ["Icode" ].(float64 )
42
42
// 进入游戏 进行匹配
43
43
fmt .Println ("玩家进行匹配!!!" )
@@ -46,6 +46,7 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
46
46
Chan_match <- int (Icode )
47
47
// 3 返回数据
48
48
data1 := Match_Player ()
49
+ _ = data1
49
50
// 4 发送数据 --> 返回数据操作
50
51
data := & Proto2.S2S_PlayerEntryGame {
51
52
Protocol : Proto .G_Snake_Proto ,
@@ -56,6 +57,10 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
56
57
}
57
58
// 发送数据给客户端了
58
59
this .PlayerSendMessage (data )
60
+ // 保存同一个玩家的数据信息
61
+ if data .RoomID != 0 {
62
+ this .MapSafe .Put (strCode + "|" + util .MD5_LollipopGO (strRoom )+ "|room" , this )
63
+ }
59
64
return
60
65
}
61
66
@@ -105,8 +110,8 @@ func (this *NetDataConn) LoginGameSnake(ProtocolData map[string]interface{}) {
105
110
// MD5信息操作
106
111
strRoom := "UID" // 玩家房间的ID信息:信息的组成主要是 游戏ID+房间ID信息 确定数据是唯一的
107
112
// 数据保存操作
108
- // --> 操作的
109
- this .MapSafe .Put (StrLogin_Name + "|" + util .MD5_LollipopGO (strRoom )+ "|connect" , "" )
113
+ // --> 操作的 ; 保存玩家信息
114
+ this .MapSafe .Put (util .MD5_LollipopGO (strRoom )+ "|connect" , this )
110
115
111
116
return
112
117
}
You can’t perform that action at this time.
0 commit comments