Example #1
0
func (self *GameBillingBw) Init(name string) bool {
	conn := self.Connect()
	tick := time.Tick(time.Second)
	for {
		select {
		case <-tick:
			if conn == nil {
				conn = self.Connect()
			}
			if conn != nil {
				self.task = bwtask.NewBwTask(conn, "BBW")
				self.task.SetHandleMessage(&handleMessageMap)
				cmd := Cmd.NewStRequestLoginBillUserCmd()
				cmd.Version = 20211111
				self.task.SendCmd(cmd)
				self.task.Id = 1 //rand.Int63()
				self.task.Name = name
				self.task.Start()
				<-self.task.StopChan
				conn = nil
			}
		}
	}
	return true
}
Example #2
0
func main() {
	raddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:7000")
	listen, err := net.ListenTCP("tcp", raddr)
	if err != nil {
		fmt.Println("listen err:", err)
		return
	}
	go func() {
		heartBeat := time.Tick(time.Second * 5)
		for {
			_, ok := <-heartBeat
			if !ok {
				fmt.Println("server heatBteat error")
				break
			}
			//fmt.Println("server heatBteat", h)
		}
	}()
	for {
		conn, err := listen.AcceptTCP()
		if err != nil {
			fmt.Println("listen error:", err)
			continue
		}
		fmt.Println("new connection:", conn.RemoteAddr())
		task := bwtask.NewBwTask(conn, "Server")
		task.Start()
	}
}
Example #3
0
func (self *GameLoginBw) Init(name string) bool {
	conn := self.Connect()
	tick := time.Tick(time.Second)
	tmpl_data = &BwGameTemplate{}
	tmpl_data.GameName = config.GetConfigStr("bw_gamename")
	tmpl_data.Starttype = config.GetConfigStr("bw_starttype")
	tmpl_data.Patchurl = config.GetConfigStr("bw_patchurl")
	tmpl_data.Allurl = config.GetConfigStr("bw_allurl")
	tmpl_data.Setuppath = config.GetConfigStr("bw_setuppath") + "#" + strconv.Itoa(int(time.Now().Unix()))
	tmpl_data.Loginaddr = config.GetConfigStr("bw_loginaddr")
	tmpl_data.Loginport = config.GetConfigStr("bw_loginport")
	tmpl_data.Configpath = config.GetConfigStr("bw_configpath")
	var err error
	tmpl, err = template.ParseFiles(config.GetConfigStr("bw_plugin") + "/templates/game.html")
	if err != nil {
		logging.Debug("open game page error:%s", err.Error())
		return false
	}
	for {
		select {
		case <-tick:
			if conn == nil {
				conn = self.Connect()
			}
			if conn != nil {
				self.task = bwtask.NewBwTask(conn, "LBW")
				self.task.SetHandleMessage(&handleMessageMap)
				cmd := Cmd.NewStRequestLoginLoginCmd()
				self.task.SendCmd(cmd)
				self.task.Id = 1 //rand.Int63()
				self.task.Name = name
				self.task.Start()
				<-self.task.StopChan
				conn = nil
			}
		}
	}
	return true
}
Example #4
0
func main() {
	raddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:7000")
	conn, err := net.DialTCP("tcp", nil, raddr)
	if err != nil {
		fmt.Println("conn err:", err)
		return
	}
	fmt.Println("new connection:", conn.RemoteAddr())
	task := bwtask.NewBwTask(conn, "Client")
	task.Id = uint64(rand.Int63())
	task.Name = conn.RemoteAddr().String()
	task.Start()
	tick := time.Tick(time.Second * 5)
	for {
		select {
		case <-tick:
			//case t := <-tick:
			//	fmt.Println(t)
		}
	}
	time.Sleep(time.Second * 10)
	task.Stop()
}