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 44 "encoding/json"
55 "fmt"
66
7+ "Proto"
8+ "Proto/Proto2"
9+
710 "code.google.com/p/go.net/websocket"
811)
912
@@ -43,6 +46,7 @@ func PlayerSendToServer(conn *websocket.Conn, data interface{}) {
4346// 群发广播函数:同一个房间
4447func PlayerSendBroadcastToRoomPlayer (iroomID int ) {
4548
49+ // 处理数据操纵
4650 // -------------------------------------------------------------------------
4751 for itr := M .Iterator (); itr .HasNext (); {
4852 k , v , _ := itr .Next ()
@@ -51,26 +55,23 @@ func PlayerSendBroadcastToRoomPlayer(iroomID int) {
5155 if len (strsplit ) < 2 {
5256 continue
5357 }
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+ { // 发送数据操作
6164 data := & Proto2.Net_Kicking_Player {
6265 Protocol : Proto .GameNet_Proto ,
6366 Protocol2 : Proto2 .Net_Kicking_PlayerProto2 ,
6467 ErrorCode : 10001 ,
6568 }
66- // 发送数据
6769 v .(interface {}).(* NetDataConn ).PlayerSendMessage (data )
6870 }
6971 }
7072 }
7173 }
7274 }
73-
7475 // -------------------------------------------------------------------------
7576 return
7677}
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
3737 panic ("玩家进入游戏数据错误, 字段为空!" )
3838 return
3939 }
40- //StrLogin_Name := ProtocolData["Code"].(string)
40+ strCode := ProtocolData ["Code" ].(string )
4141 Icode := ProtocolData ["Icode" ].(float64 )
4242 // 进入游戏 进行匹配
4343 fmt .Println ("玩家进行匹配!!!" )
@@ -46,6 +46,7 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
4646 Chan_match <- int (Icode )
4747 // 3 返回数据
4848 data1 := Match_Player ()
49+ _ = data1
4950 // 4 发送数据 --> 返回数据操作
5051 data := & Proto2.S2S_PlayerEntryGame {
5152 Protocol : Proto .G_Snake_Proto ,
@@ -56,6 +57,10 @@ func (this *NetDataConn) EntryGameSnake(ProtocolData map[string]interface{}) {
5657 }
5758 // 发送数据给客户端了
5859 this .PlayerSendMessage (data )
60+ // 保存同一个玩家的数据信息
61+ if data .RoomID != 0 {
62+ this .MapSafe .Put (strCode + "|" + util .MD5_LollipopGO (strRoom )+ "|room" , this )
63+ }
5964 return
6065}
6166
@@ -105,8 +110,8 @@ func (this *NetDataConn) LoginGameSnake(ProtocolData map[string]interface{}) {
105110 // MD5信息操作
106111 strRoom := "UID" // 玩家房间的ID信息:信息的组成主要是 游戏ID+房间ID信息 确定数据是唯一的
107112 // 数据保存操作
108- // --> 操作的
109- this .MapSafe .Put (StrLogin_Name + "|" + util .MD5_LollipopGO (strRoom )+ "|connect" , "" )
113+ // --> 操作的 ; 保存玩家信息
114+ this .MapSafe .Put (util .MD5_LollipopGO (strRoom )+ "|connect" , this )
110115
111116 return
112117}
You can’t perform that action at this time.
0 commit comments