Esempio n. 1
0
func (this *TelnetCallback) OnConnect(c *gotcp.Conn) bool {
	addr := c.GetRawConn().RemoteAddr()
	c.PutExtraData(addr)
	fmt.Println("OnConnect:", addr)
	c.AsyncWritePacket(NewTelnetPacket("unknow", []byte("Welcome to this Telnet Server")), 0)
	return true
}
Esempio n. 2
0
func on_posup(c *gotcp.Conn, p *ShaPacket) {
	log.Println("posupin")
	posup_pkg := p.Packet.(*protocol.PosUpPacket)
	if posup_pkg.WifiCount > 2 {
		posup_pkg.LocationTime = time.Now().Format("060102150405")
		sql := fmt.Sprintf("INSERT INTO t_posup_log(id, imme,location_time,datainfo,accesstype) VALUES ('%s',to_timestamp('%s','YYMMDDhh24miss'),'%s','%s')",
			posup_pkg.IMEI, posup_pkg.LocationTime, posup_pkg.Wifi, 1)
		log.Println("heihei", sql)
		GetServer().Dbsrv.Insert(sql)
		c.AsyncWritePacket(p, time.Second)
	} else if posup_pkg.GPSFlag != "" {
		c.AsyncWritePacket(p, time.Second)
		log.Println("long", posup_pkg.Longitude)
		if posup_pkg.Longitude != "" {
			log.Println("-----tag 2")
			posup_pkg.LocationTime = time.Now().Format("060102150405")
			sql := fmt.Sprintf("INSERT INTO t_posup_log(imme,location_time,glat,glong) VALUES ('%s',to_timestamp('%s','YYMMDDhh24miss'),'%s','%s')",
				posup_pkg.IMEI, posup_pkg.LocationTime, posup_pkg.Latitude, posup_pkg.Longitude)
			log.Println(sql)
			GetServer().Dbsrv.Insert(sql)
		} else if posup_pkg.WifiCount > 2 {
			log.Println("-----tag 3")
			posup_pkg.LocationTime = time.Now().Format("060102150405")
			sql := fmt.Sprintf("INSERT INTO t_posup_log(imme,location_time,datainfo,accesstype) VALUES ('%s',to_timestamp('%s','YYMMDDhh24miss'),'%s','%s')",
				posup_pkg.IMEI, posup_pkg.LocationTime, posup_pkg.Wifi, 1)
			log.Println("heihei", sql)
			GetServer().Dbsrv.Insert(sql)
		}
	}
}
Esempio n. 3
0
func (this *DasCallback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	// 0xBA command feedback 0xBB heartbeat 0xBC login
	// 0xBA cmdtype(1-8) status(0/1) serialid
	daspacket := p.(*DasPacket)
	command := daspacket.GetData()
	commandtype := daspacket.GetType()
	fmt.Println("----onmessage ", command)
	switch commandtype {
	case 0xBA:
		var result []byte
		var cmdop byte
		cmdop = command[0]*10 + command[1]
		result = append(result, cmdop)
		result = append(result, c.GetMac()...)
		result = append(result, command[3:7]...)
		result = append(result, command[2])
		c.Send(c.GetTopic(), result)

		fmt.Printf("-----recv should up the result%x \n", result)
	case 0xBB:
		c.SetTimeFlag(time.Now().Unix())
		c.AsyncWritePacket(NewDasPacket(0xAB, command), time.Second)
	case 0xBC:
		c.SetID(getMac(command), c.GetIndex())
		c.AsyncWritePacket(NewDasPacket(0xAC, command), time.Second)
	default:
		gktoolkit.Trace()
	}

	return true
}
Esempio n. 4
0
func on_login(c *gotcp.Conn, p *ShaPacket) {
	conn := c.GetExtraData().(*Conn)
	conn.Status = ConnSuccess
	loginPkg := p.Packet.(*protocol.LoginPacket)
	conn.IMEI = loginPkg.IMEI
	conn.ID, _ = strconv.ParseUint(loginPkg.IMEI, 10, 64)
	NewConns().SetID(conn.ID, conn.index)
	c.AsyncWritePacket(p, time.Second)
	time.AfterFunc(1*time.Second, func() {
		set_interval_pkg := protocol.Parse_Set_Interval(loginPkg.Encryption, loginPkg.IMEI, loginPkg.SerialNumber)
		c.AsyncWritePacket(set_interval_pkg, time.Second)
	})
}
Esempio n. 5
0
func on_warnup(c *gotcp.Conn, p *ShaPacket) {
	c.AsyncWritePacket(p, time.Second)

	warnup_pkg := p.Packet.(*protocol.WarnUpPacket)
	sql := fmt.Sprintf("INSERT INTO t_warnup_log(imme,warnstyle,warn_time) VALUES ('%s','%s',to_timestamp('%s','YYMMDDhh24miss'))",
		warnup_pkg.IMEI, warnup_pkg.WarnStyle, time.Now().Format("060102150405"))
	log.Println(sql)
	GetServer().Dbsrv.Insert(sql)

	time.AfterFunc(1*time.Second, func() {
		locate_pkg := protocol.Parse_Locate(warnup_pkg.Encryption, warnup_pkg.IMEI, warnup_pkg.SerialNumber)
		c.AsyncWritePacket(locate_pkg, time.Second)
	})

}
Esempio n. 6
0
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	shaPacket := p.(*ShaPacket)
	log.Println("onmessage packettype", shaPacket.Type)
	switch shaPacket.Type {
	case protocol.Login:
		on_login(c, shaPacket)
	case protocol.HeartBeat:
		c.AsyncWritePacket(shaPacket, time.Second)
	case protocol.PosUp:
		on_posup(c, shaPacket)
	case protocol.Echo:
		c.AsyncWritePacket(shaPacket, time.Second)
	case protocol.WarnUp:
		on_warnup(c, shaPacket)
	}

	return true
}
Esempio n. 7
0
File: conn.go Progetto: GisKook/bed
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	bedPacket := p.(*BedPacket)
	switch bedPacket.Type {
	case Login:
		c.AsyncWritePacket(bedPacket, time.Second)
	case HeartBeat:
		c.AsyncWritePacket(bedPacket, time.Second)
	case AppControlFeedback:
		GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
	case HandleControlFeedback:
		GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
	case AppPottyFeedback:
		GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
	case HandlePottyFeedback:
		GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
	case AfterPotty:
		GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
	case AppBedReset:
		GetServer().GetProducer().Send(GetServer().GetTopic(), p.Serialize())
	}

	return true
}
Esempio n. 8
0
func (this *TelnetCallback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	packet := p.(*TelnetPacket)
	command := packet.GetData()
	commandType := packet.GetType()

	switch commandType {
	case "echo":
		c.AsyncWritePacket(NewTelnetPacket("echo", command), 0)
	case "login":
		c.AsyncWritePacket(NewTelnetPacket("login", []byte(string(command)+" has login")), 0)
	case "quit":
		return false
	default:
		c.AsyncWritePacket(NewTelnetPacket("unknow", []byte("unknow command")), 0)
	}

	return true
}
Esempio n. 9
0
func (this *Callback) OnMessage(c *gotcp.Conn, p gotcp.Packet) bool {
	echoPacket := p.(*echo.EchoPacket)
	fmt.Printf("OnMessage:[%v] [%v]\n", echoPacket.GetLength(), string(echoPacket.GetBody()))
	c.AsyncWritePacket(echo.NewEchoPacket(echoPacket.Serialize(), true), time.Second)
	return true
}