예제 #1
0
func (self *ProtoProc) procClientID(cmd protocol.Cmd, session *libnet.Session) error {
	glog.Info("procClientID")
	var err error
	ID := cmd.GetArgs()[0]
	sessionStoreData := storage.NewSessionStoreData(cmd.GetArgs()[0], session.Conn().RemoteAddr().String(),
		self.msgServer.cfg.LocalIP, strconv.FormatUint(session.Id(), 10))

	glog.Info(sessionStoreData)
	args := make([]string, 0)
	args = append(args, cmd.GetArgs()[0])
	CCmd := protocol.NewCmdInternal(protocol.STORE_SESSION_CMD, args, sessionStoreData)

	glog.Info(CCmd)

	if self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS] != nil {
		_, err = self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS].Channel.Broadcast(libnet.Json(CCmd))
		if err != nil {
			glog.Error(err.Error())
			return err
		}
	}

	self.msgServer.sessions[cmd.GetArgs()[0]] = session
	self.msgServer.sessions[cmd.GetArgs()[0]].State = base.NewSessionState(true, cmd.GetArgs()[0])

	err = self.procOfflineMsg(session, ID)
	if err != nil {
		glog.Error(err.Error())
		return err
	}
	return nil
}
예제 #2
0
func (self *ProtoProc) procLogin(cmd protocol.Cmd, session *libnet.Session) error {
	log.Info("procLogin")
	var err error
	ClientID := cmd.GetArgs()[0]
	uuid := cmd.GetArgs()[1]
	resp := protocol.NewCmdSimple(protocol.RSP_LOGIN_CMD)

	// for cache data
	sessionCacheData, err := self.msgServer.sessionCache.Get(ClientID)
	if err != nil {
		log.Warningf("no ID : %s", ClientID)
	} else if sessionCacheData.ID != uuid {
		log.Warningf("ID(%s) & uuid(%s) not matched", ClientID, uuid)
		err = common.NOT_LOGIN
	}
	if err == nil {
		resp.AddArg(protocol.RSP_SUCCESS)
	} else {
		resp.AddArg(protocol.RSP_ERROR)
	}
	err2 := session.Send(libnet.Json(resp))
	if err2 != nil {
		log.Error(err2.Error())
		return err2
	}
	if err != nil {
		return err
	}
	// update the session cache
	sessionCacheData.ClientAddr = session.Conn().RemoteAddr().String()
	sessionCacheData.MsgServerAddr = self.msgServer.cfg.LocalIP
	sessionCacheData.Alive = true
	self.msgServer.sessionCache.Set(sessionCacheData)

	log.Info(sessionCacheData)

	self.msgServer.procOffline(ClientID)
	self.msgServer.procOnline(ClientID)

	/*
		args := make([]string, 0)
		args = append(args, cmd.GetArgs()[0])
		CCmd := protocol.NewCmdInternal(protocol.CACHE_SESSION_CMD, args, sessionCacheData)

		log.Info(CCmd)

		if self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS] != nil {
			_, err = self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS].Channel.Broadcast(libnet.Json(CCmd))
			if err != nil {
				log.Error(err.Error())
				return err
			}
		}

		// for store data
		sessionStoreData := mongo_store.SessionStoreData{ID, session.Conn().RemoteAddr().String(),
			self.msgServer.cfg.LocalIP, true}

		log.Info(sessionStoreData)
		args = make([]string, 0)
		args = append(args, cmd.GetArgs()[0])
		CCmd = protocol.NewCmdInternal(protocol.STORE_SESSION_CMD, args, sessionStoreData)

		log.Info(CCmd)

		if self.msgServer.channels[protocol.STORE_CLIENT_INFO] != nil {
			_, err = self.msgServer.channels[protocol.STORE_CLIENT_INFO].Channel.Broadcast(libnet.Json(CCmd))
			if err != nil {
				log.Error(err.Error())
				return err
			}
		}
	*/

	self.msgServer.sessions[ClientID] = session
	self.msgServer.sessions[ClientID].State = base.NewSessionState(true, ClientID, sessionCacheData.ClientType)

	err = self.procOfflineMsg(session, ClientID)
	if err != nil {
		log.Error(err.Error())
		return err
	}
	return nil
}