Exemple #1
0
func centerSendGetServerReq(conn net.Conn) {
	// send getserver
	var req3 PbCenter.GetServerReq
	req3.Type = proto.Int(4)
	req3.Aid = proto.Int(-1)
	req3.Sid = proto.Int(-1)
	sirius_net.SendMsg(conn, &req3, uint32(PbCenter.Command_CMD_GET_SERVER_REQ), 3)
}
func (sfl *SessionHandlerSrvRegiste) OnSessionOpened(s *netlib.Session) {
	registePacket := &protocol.SSSrvRegiste{
		Id:     proto.Int(netlib.Config.SrvInfo.Id),
		Type:   proto.Int(netlib.Config.SrvInfo.Type),
		AreaId: proto.Int(netlib.Config.SrvInfo.AreaID),
		Name:   proto.String(netlib.Config.SrvInfo.Name),
	}
	proto.SetDefaults(registePacket)
	s.Send(registePacket)
}
Exemple #3
0
func centerSendRegister(conn net.Conn) {
	// send register
	var reg PbCenter.RegReq
	var addr PbCommon.Addr

	addr.Ip = proto.String("0.0.0.0")
	addr.Port = proto.Uint32(0)
	addr.Aid = proto.Int(-1)
	addr.Sid = proto.Int(-1)
	addr.Gid = proto.Int64(-1)

	reg.Type = proto.Int(8)
	reg.Addr = &addr
	// keep dbflushd only 1
	reg.Resv = proto.Int(1)
	logger.Println(reg)
	sirius_net.SendMsg(conn, &reg, uint32(PbCenter.Command_CMD_REG_REQ), 1)
}
Exemple #4
0
func (e *Math) Square(ctx context.Context, req *math.Request, rsp *math.Response) error {
	log.Info("Received Math.Square request")

	num := req.GetNum()
	resp := num * num

	rsp.Num = proto.Int(int(resp))

	return nil
}
Exemple #5
0
func (ctx *LinkingContext) LinkRoot() {
	obj := ctx.Objects[0]
	obj.ScopeTypeId = proto.Int(ctx.textType)
	obj.Linked = proto.Bool(true)
	path := obj.GetName()
	ctx.files = append(ctx.files, path)
	localScope := make(LocalDef, 0)
	ctx.ProcessInstructionWithLocalScope(obj.Root, ctx.textType, localScope, "", path, true)
	ctx.files = ctx.files[:len(ctx.files)-1]
}
Exemple #6
0
func (ctx *LinkingContext) link(objId, scopeType int) {
	obj := ctx.Objects[objId]
	if null.GetBool(obj.Linked) == false {
		obj.ScopeTypeId = proto.Int(scopeType)
		obj.Linked = proto.Bool(true)
		path := obj.GetName()
		ctx.files = append(ctx.files, path)
		ctx.ProcessInstruction(obj.Root, scopeType, path)
		ctx.files = ctx.files[:(len(ctx.files) - 1)]
	} else {
		if scopeType != int(null.GetInt32(obj.ScopeTypeId)) {
			ctx.error("script", "Imported a script in two different scopes! Not processing second import.")
		}
	}
}
Exemple #7
0
func newTimeFormatData() *model.TimeStruct {
	current := time.Now()
	serialData := model.TimeStruct{}
	serialData.Year = proto.Int(current.Year())
	serialData.Month = proto.Int(int(current.Month()))
	serialData.Day = proto.Int(current.Day())
	serialData.Hour = proto.Int(current.Hour())
	serialData.Minitue = proto.Int(current.Minute())
	serialData.Second = proto.Int(current.Second())

	serialData.Nsec = proto.Int(current.Nanosecond())
	serialData.Format = proto.String(current.Format(time.RFC1123Z))

	return &serialData
}
Exemple #8
0
func BenchmarkClone(b *testing.B) {
	a := &StructA{IntValue: 1, StrValue: "test",
		InnerValue: &StructB{
			C:        proto.Int(9),
			IntSlice: []*int32{proto.Int(1), proto.Int(2), proto.Int(3), proto.Int(4), proto.Int(5), proto.Int(6), proto.Int(7), proto.Int(8), proto.Int(9), proto.Int(0)},
			Map:      map[int]string{1: "test", 2: "Hello"},
			StructC:  StructC{Int3: 33, DMap: map[int]*StructD{1: &StructD{Int4: 44}}},
		},
	}

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		_ = Clone(a).(*StructA)
	}
	b.StopTimer()
}
Exemple #9
0
func main() {
	// Create new request to service go.micro.service.go-template, method Example.Call
	req := client.NewRequest("sample.math", "Math.Square", &math.Request{
		Num: proto.Int(4),
	})

	// Set arbitrary headers
	req.Headers().Set("X-User-Id", "john")
	req.Headers().Set("X-From-Id", "script")

	rsp := &math.Response{}

	// Call service
	if err := client.Call(req, rsp); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(rsp.GetNum())

	// now call it using JSON RPC
	var n int32
	n = 4

	// note using standard types here, but the input protocol
	// requires a pointer to an int instead of an int
	// so we dance a little first (above)
	req1 := client.NewJsonRequest("sample.math", "Math.Square", &math.Request{
		Num: &n,
	})
	rsp = &math.Response{}
	// Call service
	if err := client.Call(req1, rsp); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(rsp.GetNum())

}
Exemple #10
0
func TestClone(t *testing.T) {
	a := &StructA{IntValue: 1, StrValue: "test",
		InnerValue: &StructB{
			C:        proto.Int(9),
			IntSlice: []*int32{proto.Int(1), proto.Int(2), proto.Int(3), proto.Int(4), proto.Int(5), proto.Int(6), proto.Int(7), proto.Int(8), proto.Int(9), proto.Int(0)},
			Map:      map[int]string{1: "test", 2: "Hello"},
			StructC:  StructC{Int3: 33, DMap: map[int]*StructD{1: &StructD{Int4: 44}}},
		},
	}
	b := Clone(a).(*StructA)
	//t.Trace(a, b)

	b.InnerValue.IntSlice[0] = proto.Int(99)
	b.InnerValue.IntSlice = b.InnerValue.IntSlice[:7]
	//t.Tracef("%#v %#v %#v\r\n", a, a.InnerValue.IntSlice, *a.InnerValue.C)
	//t.Tracef("%#v %#v %#v\r\n", b, b.InnerValue.IntSlice, *b.InnerValue.C)
	//t.Tracef("%#v\r\n", a.InnerValue.Map)
	//t.Tracef("%#v\r\n", b.InnerValue.Map)
	//t.Tracef("%#v\r\n", a.InnerValue.StructC)
	//t.Tracef("%#v\r\n", b.InnerValue.StructC)
}
func main() {
	addr := "203.117.155.97:9100"
	userIdStr := ""
	if len(os.Args) > 1 {
		userIdStr = os.Args[1]
	}
	data, err := ioutil.ReadFile("DeleteUser.xml")
	if err == nil {
		var config Config
		err = xml.Unmarshal(data, &config)
		if err == nil {
			addr = config.Addr
			if userIdStr == "" {
				userIdStr = config.Userid
			}
		}
	}
	if err != nil {
		log.Print(err, " use default configuration")
	}
	userId, err := strconv.Atoi(userIdStr)
	if err != nil {
		log.Fatal("wrong userid ", err)
	}
	log.Print("send DeleteUser ", userId, " command to ", addr)
	tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
	if err != nil {
		log.Fatal("resolve error ", err)
	}
	conn, err := net.DialTCP("tcp", nil, tcpAddr)
	if err != nil {
		log.Fatal("connect error ", err)
	}
	conn.SetReadDeadline(time.Now().Add(time.Second * 5))
	deleteUser := &Auth_C2S.DeleteAccount{Userid: proto.Int(userId)}
	sendMsg(conn, byte(C2S_DeleteAccount_CMD), deleteUser)
	readReply(conn)
}
Exemple #12
0
func (ctx *LinkingContext) ProcessInstructionWithLocalScope(ins *tp.Instruction, scopeType int, localScope LocalDef, caller string, path string, justRoot bool) (returnType int) {
	returnType = -1
	ins.IsValid = proto.Bool(true)
	switch *ins.Type {
	case constants.Instruction_IMPORT:
		importLocation := ins.GetValue()

		// keep track of which files we're inside of, to detect circular imports
		val, present := ctx.Visiting[importLocation]
		if present && val {
			ctx.error(ins, "Circular import detected: %s", importLocation)
			panic(fmt.Sprintf("Circular import detected: %s", importLocation))
		}
		ctx.Visiting[importLocation] = true

		importId, ok := ctx.objMap[importLocation]
		if ok != true {
			ctx.error(ins, "Invalid import `%s`", ins.String())
		}
		// if we're linking the whole tree, then recurse
		if !justRoot {
			// Make sure this object is linked with the right scopeType
			ctx.link(importId, scopeType)

			// otherwise just set the script object's scope type
		} else {
			ctx.Objects[importId].ScopeTypeId = proto.Int(scopeType)
		}

		// pop the import stack (for circular import detection)
		ctx.Visiting[importLocation] = false

		ins.ObjectId = proto.Int(importId)
		ins.Value = nil
	case constants.Instruction_LOCAL_VAR:
		name := null.GetString(ins.Value)
		if name == "1" || name == "2" || name == "3" || name == "4" || name == "5" || name == "6" || name == "7" {
			if len(ins.Arguments) > 0 {
				// We are going to assign something to this variable
				returnType = ctx.ProcessInstructionWithLocalScope(ins.Arguments[0], scopeType, localScope, caller, path, justRoot)
				if returnType != ctx.textType {
					ctx.error(ins, "Numeric local vars can ONLY be Text")
				}
			}
			if ins.Children != nil {
				for _, child := range ins.Children {
					ctx.ProcessInstructionWithLocalScope(child, ctx.textType, localScope, caller, path, justRoot)
				}
			}
			returnType = ctx.textType
		} else { // Not numeric.
			typeId, found := localScope[name]
			if found {
				returnType = typeId
				if len(ins.Arguments) > 0 {
					ctx.error(ins, "The local variable \"%%%s\" has been assigned before and cannot be reassigned! Open a scope on it if you need to alter the contents.", name)
				} else {
					if ins.Children != nil {
						for _, child := range ins.Children {
							returnType = ctx.ProcessInstructionWithLocalScope(child, typeId, localScope, caller, path, justRoot)
						}
					}
				}

			} else {
				if len(ins.Arguments) > 0 {
					// We are going to assign something to this variable
					// But first, check for possible mutation and prevent it for now.
					if ins.Children != nil {
						ctx.error(ins, "May not open a scope during initialization of local variable \"%%%s\".", name)
					}
					returnType = ctx.ProcessInstructionWithLocalScope(ins.Arguments[0], scopeType, localScope, caller, path, justRoot)
					localScope[name] = returnType
				} else {
					ctx.error(ins, "I've never seen the variable \"%%%s\" before! Please assign a value before usage.", name)
				}
			}
		}

	case constants.Instruction_FUNCTION_CALL:
		stub := null.GetString(ins.Value)
		if stub == "yield" {
			ins.YieldTypeId = proto.Int32(int32(scopeType))
		}
		namespaces := ins.Namespaces()
		// ins.Namespace = nil // need to figure out where to do this step
		// process the args
		if ins.Arguments != nil {
			for _, arg := range ins.Arguments {
				argReturn := ctx.ProcessInstructionWithLocalScope(arg, scopeType, localScope, caller, path, justRoot)
				if argReturn == -1 {
					ctx.error(ins, "Invalid argument object %q", arg.String())
					return
				}
				stub = stub + "," + ctx.types[argReturn]
			}
		}
		// for each namespace specified by the user, look up the function wrt the current context type + function name
		var funcId int
		var ok bool
		for _, ns := range namespaces {
			funcId, ok = ctx.funList[scopeType][ns+"."+stub]
			if ok {
				break
			}
		}

		if !ok {
			readableCalleeStub := readableStub(stub)
			readableCallerStub := readableStub(caller)

			location := ""
			if len(path) > 0 {
				location = path
			} else {
				location = "Package " + ctx.Pkg.GetName()
			}

			msg := fmt.Sprintf("%s:%d: function %s.%s does not exist in namespace %s", location, ins.GetLineNumber(), ctx.types[scopeType], readableCalleeStub, namespaces[0])
			for i := 1; i < len(namespaces)-1; i++ {
				msg += ", " + namespaces[i]
			}
			if len(namespaces) > 1 {
				msg += " or " + namespaces[len(namespaces)-1]
			}
			msg += fmt.Sprintf("; (called from %s.%s).", ctx.types[scopeType], readableCallerStub)

			ctx.error(ins, msg)

			// message := fmt.Sprintf("Available functions in %s.%s:\n", ns, ctx.types[scopeType])
			// ns := strings.SplitN(stub, ".", 2)[0]
			// nsPrefix := ns + "."
			// for funcName, _ := range ctx.funList[scopeType] {
			// 	if strings.HasPrefix(funcName, nsPrefix) {
			// 		message += "\t" + nsPrefix + readableStub(funcName) + "\n"
			// 	}
			// }
			// log.Printf("%s\n", message)

			// ctx.error(ins, "%s:%d: could not find function %s.%s.%s (called from %s.%s.%s)", location, ins.GetLineNumber(), ns, ctx.types[scopeType], readableCalleeStub, callerNamespace, ctx.types[scopeType], readableCallerStub)

		} else {
			ins.FunctionId = proto.Int32(int32(funcId))
			fun := ctx.Pkg.Functions[funcId]
			returnType = int(null.GetInt32(fun.ReturnTypeId))
			opensScopeType := int(null.GetInt32(fun.OpensTypeId))
			if opensScopeType == 0 {
				// If we're a Base scope, don't mess with texas!
				opensScopeType = scopeType
			}
			// If it inherits:
			inheritedOpensScopeType := ctx.Pkg.FindDescendantType(int32(opensScopeType))
			if inheritedOpensScopeType != -1 {
				opensScopeType = inheritedOpensScopeType
			}

			// Copy the local scope
			parentScope := localScope
			localScope = make(LocalDef, len(parentScope))
			for s, t := range parentScope {
				localScope[s] = t
			}

			if ins.Children != nil {
				for _, child := range ins.Children {
					ctx.ProcessInstructionWithLocalScope(child, opensScopeType, localScope, stub, path, justRoot) // thread the name of the caller through the linkages
				}
			}
		}
	case constants.Instruction_TEXT:
		returnType = ctx.textType
	case constants.Instruction_BLOCK:
		if ins.Children != nil {
			for _, child := range ins.Children {
				returnType = ctx.ProcessInstructionWithLocalScope(child, scopeType, localScope, caller, path, justRoot)
			}
		}
	}
	return
}
Exemple #13
0
func centerSendNotifyReg(conn net.Conn) {
	// send notifyreg
	var req2 PbCenter.RegNotifyReq
	req2.Type = proto.Int(4)
	sirius_net.SendMsg(conn, &req2, uint32(PbCenter.Command_CMD_REG_NOTIFY_REQ), 2)
}