Пример #1
0
//发送Log消息到LogServer
func sendLogMsgToServer(msg []byte) {
	if logClient == nil {
		serverMsgDispatch.Process(nil, msg)
	} else {
		protos.Send(logClient, msg)
	}
}
Пример #2
0
//发送连接DB服务器
func sendConnectDBServer() {
	INFO(global.ServerName + " Connect DBServer ...")
	send_msg := protos.MarshalProtoMsg(&systemProto.System_ConnectDBServerC2S{
		ServerName: protos.String(global.ServerName),
	})
	protos.Send(dbClient, send_msg)
}
Пример #3
0
func init() {
	handle := dispatch.NewHandleConditions()
	//系统消息处理
	handle.Add(dispatch.HandleCondition{
		Condition: systemProto.IsValidID,
		H: dispatch.Handle{
			systemProto.ID_System_ConnectWorldServerS2C: connectWorldServerCallBack,
		},
	})
	//游戏消息处理
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidID,
		H: func(session *link.Session, msg []byte) {
			//发送到用户客户端
			msgIdentification := binary.GetUint64LE(msg[2:10])
			userSession := global.GetSession(msgIdentification)
			if userSession == nil {
				return
			}
			protos.Send(userSession, msg)
		},
	})

	//创建消息分派
	clientMsgDispatch = dispatch.NewDispatch(handle)
}
Пример #4
0
//发送DB消息到客户端
func sendDBMsgToClient(session *link.Session, msg []byte) {
	if session == nil {
		clientMsgDispatch.Process(session, msg)
	} else {
		protos.Send(session, msg)
	}
}
Пример #5
0
//发送DB消息到服务器
func sendDBMsgToServer(msg []byte) {
	if dbClient == nil {
		serverMsgDispatch.Process(nil, msg)
		serverMsgDispatchAsync.Process(nil, msg)
	} else {
		protos.Send(dbClient, msg)
	}
}
Пример #6
0
//重新连接
func againConnect(session *link.Session, msg protos.ProtoMsg) {
	rev_msg := msg.Body.(*gameProto.AgainConnectC2S)

	newSessionID := module.User.AgainConnect(rev_msg.GetSessionID(), session)
	if newSessionID != 0 {
		send_msg := protos.MarshalProtoMsg(&gameProto.AgainConnectS2C{
			SessionID: protos.Uint64(newSessionID),
		})
		protos.Send(session, send_msg)
	}
}
//其他客户端连接TransferServer处理
func connectTransferServer(session *link.Session, protoMsg protos.ProtoMsg) {
	rev_msg := protoMsg.Body.(*systemProto.System_ConnectTransferServerC2S)

	serverName := rev_msg.GetServerName()
	serverID := rev_msg.GetServerID()

	useServerName := strings.Split(serverName, "[")[0]
	serverList, exists := servers[useServerName]
	if !exists {
		serverList = make([]Server, 0, 10)
	}
	server := Server{
		session:     session,
		serverID:    serverID,
		serverIndex: len(serverList),
	}
	serverList = append(serverList, server)
	servers[useServerName] = serverList

	//服务器断开连接处理
	session.AddCloseCallback(session, func() {
		serverList = append(serverList[:server.serverIndex], serverList[server.serverIndex+1:]...)
		servers[useServerName] = serverList
		ERR(serverName + " Disconnect At " + global.ServerName)
	})

	//GameServer可以有多个
	if useServerName == "GameServer" {
		addr := strings.Split(session.Conn().RemoteAddr().String(), ":")
		addrIp := addr[0]
		addrPort, _ := strconv.Atoi(addr[1])
		gameNode := hashs.NewNode(server.serverIndex, addrIp, addrPort, serverName, 1)
		gameConsistent.Add(gameNode)

		//GameServer断开连接处理
		session.AddCloseCallback(session, func() {
			//移除此Node
			gameConsistent.Remove(gameNode)
			//将此Node的所有用户断开连接
			for clientSessionID, gameNodeIndex := range gameUserSessions {
				if server.serverIndex == gameNodeIndex {
					clientSession := global.GetSession(clientSessionID)
					if clientSession != nil {
						clientSession.Close()
					}
				}
			}
		})
	}

	//发送连接成功消息
	send_msg := protos.MarshalProtoMsg(&systemProto.System_ConnectTransferServerS2C{})
	protos.Send(session, send_msg)
}
Пример #8
0
//其他客户端连接LogServer处理
func connectLogServer(session *link.Session, protoMsg protos.ProtoMsg) {
	rev_msg := protoMsg.Body.(*systemProto.System_ConnectLogServerC2S)

	serverName := rev_msg.GetServerName()
	servers[serverName] = session

	session.AddCloseCallback(session, func() {
		delete(servers, serverName)
		ERR(serverName + " Disconnect At " + global.ServerName)
	})

	send_msg := protos.MarshalProtoMsg(&systemProto.System_ConnectLogServerS2C{})
	protos.Send(session, send_msg)
}
Пример #9
0
//发送获取用户数据结果
func SendGetUserInfoResult(session *link.Session, errorCode int32, u *UserModel) {
	if errorCode != 0 {
		SendErrorMsg(session, errorCode)
	} else {
		send_msg := protos.MarshalProtoMsg(&gameProto.GetUserInfoS2C{
			UserInfo: &gameProto.Person{
				ID:        protos.Uint64(u.DBUser.ID),
				Name:      protos.String(u.DBUser.Name),
				Money:     protos.Int32(u.DBUser.Money),
				SessionID: protos.Uint64(session.Id()),
			},
		})
		protos.Send(session, send_msg)
	}
}
//发送系统消息到TransferServer
func sendSystemMsgToServer(msg []byte) {
	if transferClient == nil {
		return
	}
	protos.Send(transferClient, msg)
}
Пример #11
0
//发送游戏消息到WorldServer
func SendGameMsgToServer(msg []byte) {
	if worldClient == nil {
		return
	}
	protos.Send(worldClient, msg)
}
Пример #12
0
//发送登录结果
func SendLoginResult(session *link.Session, userID uint64) {
	send_msg := protos.MarshalProtoMsg(&gameProto.UserLoginS2C{
		UserID: protos.Uint64(userID),
	})
	protos.Send(session, send_msg)
}
Пример #13
0
//发送服务器连接成功
func SendConnectSuccess(session *link.Session) {
	protos.Send(session, protos.MarshalProtoMsg(&gameProto.ConnectSuccessS2C{}))
}
Пример #14
0
//发送其他客户端登录
func SendOtherLogin(session *link.Session) {
	protos.Send(session, protos.MarshalProtoMsg(&gameProto.OtherLoginS2C{}))
}
Пример #15
0
//发送通用错误消息
func SendErrorMsg(session *link.Session, errID int32) {
	send_msg := protos.MarshalProtoMsg(&gameProto.ErrorMsgS2C{
		ErrorID: protos.Int32(errID),
	})
	protos.Send(session, send_msg)
}
Пример #16
0
//发送系统消息到LogServer
func sendSystemMsgToServer(msg []byte) {
	if logClient == nil {
		return
	}
	protos.Send(logClient, msg)
}