本文整理匯總了Golang中github.com/funny/link.Session類的典型用法代碼示例。如果您正苦於以下問題:Golang Session類的具體用法?Golang Session怎麽用?Golang Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Session類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleMsgServerClient
func (self *Manager) handleMsgServerClient(msc *link.Session) {
msc.ReadLoop(func(msg link.InBuffer) {
glog.Info("msg_server", msc.Conn().RemoteAddr().String(), "say:", string(msg.Get()))
self.parseProtocol(msg.Get(), msc)
})
}
示例2: connectTransferServer
//其他客戶端連接TransferServer處理
func connectTransferServer(session *link.Session, protoMsg systemProto.ProtoMsg) {
rev_msg := protoMsg.Body.(*systemProto.System_ConnectTransferServerC2S)
serverName := rev_msg.GetServerName()
INFO(serverName + " Connect TransferServer")
useServerName := strings.Split(serverName, "[")[0]
sessions, exists := servers[useServerName]
if !exists {
sessions = make([]*link.Session, 0, 10)
}
sessions = append(sessions, session)
servers[useServerName] = sessions
//GameServer可以有多個
if useServerName == "GameServer" {
addr := strings.Split(session.Conn().RemoteAddr().String(), ":")
addrIp := addr[0]
addrPort, _ := strconv.Atoi(addr[1])
gameConsistent.Add(hashs.NewNode(len(sessions), addrIp, addrPort, serverName, 1))
}
send_msg := systemProto.MarshalProtoMsg(&systemProto.System_ConnectTransferServerS2C{})
systemProto.Send(send_msg, session)
startDealReceiveMsgC2S(session)
}
示例3: newFrontLink
func newFrontLink(session *link.Session, linkID uint64) *frontendLink {
flink := &frontendLink{
session: session,
linkId: linkID,
clients: make(map[uint64]*link.Session),
clientWaits: make(map[uint64]*link.Session),
}
session.AddCloseCallback(flink, func() {
flink.Close()
})
go func() {
var msg = gatewayMsg{}
for {
if err := session.Receive(&msg); err != nil {
break
}
switch msg.Command {
case CMD_MSG:
flink.dispathMsg(msg.ClientId, msg.Data)
case CMD_BRD:
flink.broadcast(msg.ClientIds, msg.Data)
case CMD_NEW_2:
flink.newClient(msg.ClientId, msg.ClientIds[0])
case CMD_DEL:
flink.delClient(msg.ClientId, false)
}
}
flink.Close()
}()
return flink
}
示例4: Login
//登錄
func (this UserModule) Login(userName string, session *link.Session) {
onlineUser := module.Cache.GetOnlineUserByUserName(userName)
if onlineUser != nil {
if onlineUser.Session.Id() != session.Id() {
//當前在線,但是連接不同,其他客戶端連接,需通知當前客戶端下線
module.SendOtherLogin(onlineUser.Session)
//替換Session
module.Cache.RemoveOnlineUser(onlineUser.Session.Id())
//登錄成功處理
success := loginSuccess(session, onlineUser.UserName, onlineUser.UserID)
if success {
module.SendLoginResult(onlineUser.UserID, session)
} else {
module.SendLoginResult(0, session)
}
}
} else {
cacheDbUser := redisProxy.GetDBUserByUserName(userName)
if cacheDbUser != nil {
this.UserLoginHandle(session, cacheDbUser.Name, cacheDbUser.ID)
} else {
dbProxy.UserLogin(session.Id(), userName)
}
}
}
示例5: SetClientSessionOnline
//LoginServer用戶上線
func SetClientSessionOnline(userSession *link.Session) {
//發送用戶上線消息到serverName
protoMsg := &systemProto.System_ClientSessionOnlineC2S{
SessionID: protos.Uint64(userSession.Id()),
Network: protos.String(userSession.Conn().RemoteAddr().Network()),
Addr: protos.String(userSession.Conn().RemoteAddr().String()),
}
send_msg := protos.MarshalProtoMsg(protoMsg)
sendSystemMsg2("LoginServer", 0, send_msg)
}
示例6: sessionReceive
func sessionReceive(session *link.Session, d dispatch.DispatchInterface) {
for {
var msg []byte
if err := session.Receive(&msg); err != nil {
break
}
d.Process(session, msg)
}
}
示例7: handleSession
func handleSession(ms *MsgServer, session *link.Session) {
session.ReadLoop(func(msg link.InBuffer) {
glog.Info(string(msg.Get()))
err := ms.parseProtocol(msg.Get(), session)
if err != nil {
glog.Error(err.Error())
}
})
}
示例8: AddSession
func AddSession(session *link.Session) {
sessionMutex.Lock()
defer sessionMutex.Unlock()
sessionNum += 1
sessions[session.Id()] = session
session.AddCloseCallback(session, func() {
RemoveSession(session)
sessionNum -= 1
})
}
示例9: SetClientLoginSuccess
//通知GameServer用戶登錄成功
func SetClientLoginSuccess(userName string, userID uint64, session *link.Session) {
send_msg := protos.MarshalProtoMsg(&systemProto.System_ClientLoginSuccessC2S{
UserID: protos.Uint64(userID),
UserName: protos.String(userName),
SessionID: protos.Uint64(session.Id()),
GameServerID: protos.Uint32(0),
Network: protos.String(session.Conn().RemoteAddr().Network()),
Addr: protos.String(session.Conn().RemoteAddr().String()),
})
sendSystemMsgToServer(send_msg)
}
示例10: BytesTest
func BytesTest(t *testing.T, session *link.Session) {
for i := 0; i < 2000; i++ {
msg1 := RandBytes(512)
err := session.Send(msg1)
unitest.NotError(t, err)
var msg2 []byte
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, bytes.Equal(msg1, msg2))
}
}
示例11: ObjectTest
func ObjectTest(t *testing.T, session *link.Session) {
for i := 0; i < 2000; i++ {
msg1 := RandObject()
err := session.Send(&msg1)
unitest.NotError(t, err)
var msg2 TestObject
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, msg1 == msg2)
}
}
示例12: StringTest
func StringTest(t *testing.T, session *link.Session) {
for i := 0; i < 2000; i++ {
msg1 := string(RandBytes(512))
err := session.Send(msg1)
unitest.NotError(t, err)
var msg2 string
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, msg1 == msg2)
}
}
示例13: AddClient
func (flink *frontendLink) AddClient(session *link.Session) {
flink.clientMutex.Lock()
defer flink.clientMutex.Unlock()
flink.clientWaitId += 1
flink.clientWaits[flink.clientWaitId] = session
addr := session.Conn().RemoteAddr()
flink.session.Send(&gatewayMsg{
Command: CMD_NEW_1, ClientId: flink.clientWaitId,
Data: []byte(addr.Network() + "," + addr.String()),
})
}
示例14: dealLoginSuccess
//登錄成功後處理
func (this UserModule) dealLoginSuccess(session *link.Session, userName string, userID uint64) {
//通知GameServer登錄成功
transferProxy.SetClientLoginSuccess(userName, userID, session)
//發送登錄成功消息
gameProxy.SendLoginResult(session, userID)
//用戶下線時處理
session.AddCloseCallback(session, func() {
//記錄用戶下線Log
logProxy.UserOffLine(userID)
})
//記錄用戶登錄Log
logProxy.UserLogin(userID)
}
示例15: LoginSuccess
//用戶登錄成功處理
func (this UserModule) LoginSuccess(session *link.Session, userName string, userID uint64, gameServerID uint32) bool {
cacheSuccess := module.Cache.AddOnlineUser(userName, userID, session, gameServerID)
if cacheSuccess {
session.AddCloseCallback(session, func() {
module.Cache.RemoveOnlineUser(session.Id())
DEBUG("用戶下線:當前在線人數", module.Cache.GetOnlineUsersNum())
})
DEBUG("用戶上線:當前在線人數", module.Cache.GetOnlineUsersNum())
return true
} else {
ERR("what????", userName)
return false
}
}