Esempio n. 1
0
func (c *ClientSession) SendResponse(command uint32, da interface{}) {
	var data []byte
	var err error
	var newdata []byte
	var final []byte
	var buffer *bytes.Buffer
	buffer = bytes.NewBuffer(data)
	// write length first
	buffer.Write(utils.Uint16ToBytes(uint16(len(newdata))))
	if ServerBs.SPipelineConfig.Proto != nil {
		newdata, err = ServerBs.SPipelineConfig.Proto.DoEncode(da)
		if err != nil {
		}
	}
	// write command and data
	buffer.Write(utils.Uint32ToBytes(uint32(command)))
	buffer.Write(newdata)
	if ServerBs.SPipelineConfig.Cipher != nil {
		// encrypt some bytes
		final, err = ServerBs.SPipelineConfig.Cipher.DoEncrypt(buffer.Bytes()[2:])
		if err != nil {
		}
	} else {
		final = buffer.Bytes()[0:]
	}

	// to bufio
	c.writeChan <- final
}
Esempio n. 2
0
func main() {
	aaa := abc{"1", "2", 3}
	//	var bca interface{}
	//	bca = aaa
	//	m := Message{"Alice", "Hello", 1294706395881547000}
	msg, _ := utils.EncodeJson(aaa)
	fmt.Println(string(msg))
	c28, _ := utils.DecodeJson(msg)
	fmt.Println("c28:", c28)
	var c30 abc
	fmt.Println("c28.A:", c28["a"])
	fmt.Println("c28.C:", c28["c"])
	c30.A = c28["a"].(string)
	c30.C = int(c28["c"].(float64))
	fmt.Println("c30.A:", c30.A)
	fmt.Println("c30.C:", c30.C)
	err := json.Unmarshal(msg, &c30)

	fmt.Println(reflect.TypeOf(c28))

	for _, val := range c28 {
		val2 := reflect.ValueOf(val) //.FieldByName(val)
		fmt.Println("suck", val2)
	}

	for i := 0; i < reflect.ValueOf(c30).NumField(); i++ {
		//		val2 := reflect.ValueOf(val)//.FieldByName(val)
		fmt.Println("suck2", reflect.ValueOf(c30).Field(i))
	}

	//	fmt.Println("s")
	//	go server.ServerBs.InitWithConfigFile("config.xml")

	//	abcd := server.ServerBs
	//	abc := server.DefaultServerCommon()
	//	abc.Start()
	//	abcd.ServerParam = abc
	var c1 interface{}
	var c2 protocol
	var c3 *protocol
	//	var c4 protocol
	c1 = 1
	c2 = &JsonProtocol{}
	c3 = &c2
	fmt.Println(reflect.TypeOf(c1))
	fmt.Println(reflect.TypeOf(c2))
	fmt.Println(reflect.TypeOf(c3))

	fmt.Println(reflect.ValueOf(c1))
	fmt.Println(reflect.ValueOf(c2))
	fmt.Println(reflect.ValueOf(c3))

	db := []byte("*****@*****.**")
	//	key := "sfe023f_"
	var des server.Crypt
	des = &crypto.MiscCipher{Key: 0xA55AA55A}
	fmt.Println(reflect.TypeOf(reflect.TypeOf(des)))

	//	var chiper *server.Crypt
	//	chiper = &des

	result, err := des.DoEncrypt(db)
	fmt.Println("current:", string(result))
	if err != nil {
		panic(err)
	}
	//	fmt.Println(base64.StdEncoding.EncodeToString(result))
	origData, err := des.DoDecrypt(result)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(origData))
	fmt.Println(utils.BytesToUint16([]byte{1, 255}))
	fmt.Println(utils.Uint16ToBytes(511))
	server.ServerBs.InitWithConfigFile("config.xml")
	//	server.ServerBs.Start()
	//	select{}
}