Beispiel #1
0
    private List <UserVariable> ReadUserVariables(BinaryReader reader)
    {
        bool error                      = false;
        long startPos                   = reader.BaseStream.Position;
        int  numChangedVars             = reader.ReadInt32();
        List <UserVariable> changedVars = new List <UserVariable>(numChangedVars);

        for (int i = 0; i < numChangedVars && !error; ++i)
        {
            try {
                string       varName = reader.ReadString();
                VariableType varType = (VariableType)reader.ReadInt32();
                object       obj     = null;
                switch (varType)
                {
                case VariableType.INT:
                    obj = reader.ReadInt32();
                    break;

                case VariableType.DOUBLE:
                    obj = reader.ReadDouble();
                    break;

                case VariableType.STRING:
                    obj = reader.ReadString();
                    break;

                case VariableType.OBJECT:
                    int    len      = reader.ReadInt32();
                    byte[] objBytes = reader.ReadBytes(len);
                    obj = SFSObject.NewFromBinaryData(new ByteArray(objBytes));
                    break;

                default:
                    Debug.LogError("Caught unknown variable type: " + (int)varType);
                    error = true;
                    break;
                }
                if (!error)
                {
                    SFSUserVariable uv = new SFSUserVariable(varName, obj, (int)varType);
                    changedVars.Add(uv);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Caught exception reading user variable: " + e.ToString());
                error = true;
            }
        }
        if (error)
        {
            reader.BaseStream.Position = startPos + 1;
            FindNextValidMessage(reader, startFileTime);
        }
        return(changedVars);
    }
    public void Cancel()
    {
        UserVariable uv = new SFSUserVariable("Ready", "NO");
        List<UserVariable> lUV = new List<UserVariable>();
        lUV.Add(uv);
        sfs.Send(new SetUserVariablesRequest(lUV));

        RoomVariable rv = new SFSRoomVariable("ReadyCount", int.Parse(sfs.LastJoinedRoom.GetVariable("ReadyCount").Value.ToString()) - 1);
        List<RoomVariable> lRV = new List<RoomVariable>();
        lRV.Add(rv);
        sfs.Send(new SetRoomVariablesRequest(lRV));

        ISFSObject isfsO = new SFSObject();
        isfsO.PutInt("Sender", sfs.MySelf.PlayerId);
        sfs.Send(new PublicMessageRequest("PlayerCancel", isfsO, sfs.LastJoinedRoom));
    }
Beispiel #3
0
        public static User FromSFSArray(ISFSArray sfsa, Room room)
        {
            User user = new SFSUser(sfsa.GetInt(0), sfsa.GetUtfString(1));

            user.PrivilegeId = sfsa.GetShort(2);
            if (room != null)
            {
                user.SetPlayerId(sfsa.GetShort(3), room);
            }
            ISFSArray sFSArray = sfsa.GetSFSArray(4);

            for (int i = 0; i < sFSArray.Size(); i++)
            {
                user.SetVariable(SFSUserVariable.FromSFSArray(sFSArray.GetSFSArray(i)));
            }
            return(user);
        }
Beispiel #4
0
    void OnGUI()
    {
        GUI.skin = skin;
        guiColor = Color.white;
        GUIStyle tStyle = new GUIStyle(GUI.skin.button);

        if (loginStep < 4)
        {
            GUI.Label(new Rect((Screen.width - titleTexture.width) / 2, 100, titleTexture.width, titleTexture.height), titleTexture);
        }

        if (errorMsg != null)
        {
            GUIStyle lStyle    = new GUIStyle(GUI.skin.label);
            Vector2  labelSize = lStyle.CalcSize(new GUIContent(errorMsg));
            GUI.contentColor = Color.red;

            GUI.Label(new Rect((Screen.width - labelSize.x) / 2, Screen.height * 2 / 3, labelSize.x, labelSize.y), errorMsg);
            GUI.contentColor = Color.white;
        }

        if (loginStep == 1)
        {
            GUI.Label(new Rect((Screen.width - titleTexture.width) / 2 + 20, (Screen.height - titleTexture.height) / 2 + 32, 500, 40), "Username");

            if (usernameEnabled == true)
            {
                username = GUI.TextField(new Rect((Screen.width - titleTexture.width) / 2 + 20, (Screen.height - titleTexture.height) / 2 + 64, titleTexture.width * .6f, buttonPlay.height), username, 25);
            }

            if (playButtonPressed)
            {
                guiColor.a     = 0.5f;
                GUI.color      = guiColor;
                tStyle.padding = new RectOffset(1, 1, 1, 1);
            }
            else
            {
                tStyle.padding = new RectOffset();
            }

            if (GUI.Button(new Rect((Screen.width - titleTexture.width) / 2 + titleTexture.width * .67f, (Screen.height - titleTexture.height) / 2 + 64, buttonPlay.width, buttonPlay.height), buttonPlay, tStyle) && !playButtonPressed)
            {
                playButtonPressed = true;
                if (sfs == null)
                {
                    // Attempt connection
                    DoConnect();
                }
                else
                {
                    // Skip the connection and attempt login
                    sfs.Send(new LoginRequest(username, "", "SpaceWar"));
                }
            }
            guiColor.a = 1f;
            GUI.color  = guiColor;
        }

        if (loginStep == 2)
        {
            GUI.Label(new Rect((Screen.width - titleTexture.width) / 2 + 150, (Screen.height - titleTexture.height) * 2 / 5, titleTexture.width * .6f, buttonPlay.height), "Select your starship");
            Array models = starshipModels.GetKeys();
            for (int i = 0; i < models.Length; i++)
            {
                ISFSObject starship = starshipModels.GetSFSObject(models.GetValue(i) as String);

                Texture2D btnTexture = buttonAstro;
                switch (starship.GetUtfString("model"))
                {
                case "Astro":
                    btnTexture = buttonAstro;
                    break;

                case "Viking":
                    btnTexture = buttonViking;
                    break;

                case "Raptor":
                    btnTexture = buttonRaptor;
                    break;
                }

                GUI.Label(new Rect((Screen.width - titleTexture.width) / 2 + 70 + i * 200, (Screen.height - titleTexture.height) / 2 + 55, 150, 40), starship.GetUtfString("model"));
                if (GUI.Button(new Rect((Screen.width - titleTexture.width) / 2 + 80 + i * 200, (Screen.height - titleTexture.height) / 2, btnTexture.width, btnTexture.height), btnTexture))
                {
                    UserVariable        shipModelUV = new SFSUserVariable(UV_MODEL, starship.GetUtfString("model"));
                    List <UserVariable> userVars    = new List <UserVariable>();
                    userVars.Add(shipModelUV);
                    sfs.Send(new SetUserVariablesRequest(userVars));
                }
            }
        }

        if (loginStep == 3)
        {
            GUI.Label(new Rect((Screen.width - titleTexture.width) / 2 + 140, (Screen.height - titleTexture.height) * 2 / 5, titleTexture.width * .6f, buttonPlay.height), "Select a solar system");

            // Room select
            for (int i = 0; i < sfs.RoomList.Count; i++)
            {
                Room room = sfs.RoomList[i] as Room;
                GUI.Label(new Rect((Screen.width - titleTexture.width) / 2 + 290 + i * 200, (Screen.height - titleTexture.height) / 2 + 170, 150, 40), room.Name);
                if (GUI.Button(new Rect((Screen.width - titleTexture.width) / 2 + 240 + i * 200, (Screen.height - titleTexture.height) / 2, buttonSol.width, buttonSol.height), buttonSol))
                {
                    // Join the corresponding MMORoom
                    sfs.Send(new JoinRoomRequest(room.Name));
                }
            }
        }
    }
Beispiel #5
0
 void SendUpdatePositionMessage()
 {
     UserVariable xPos = new SFSUserVariable ("x", transform.position.x.ToString());
     UserVariable yPos = new SFSUserVariable ("y", transform.position.y.ToString());
     UserVariable zPos = new SFSUserVariable ("z", transform.position.z.ToString());
     List<UserVariable> list = new List<UserVariable> ();
     list.Add (xPos);
     list.Add (yPos);
     list.Add (zPos);
     sfs.Send (new SetUserVariablesRequest(list));
 }
    private void SendRegistrationRequest(object data)
    {
        Dictionary<string, string> cdata = data as Dictionary<string, string>;
        SFSObject sfsdata = new SFSObject();
        sfsdata.PutUtfString("user_name", cdata["username"]);
        sfsdata.PutUtfString("user_password", cdata["password"]);
        sfsdata.PutUtfString("user_email", cdata["email"]);

        SFSUserVariable userVar = new SFSUserVariable("username", cdata["username"]);
        SFSInstance.MySelf.SetVariable(userVar);

        SFSInstance.Send(new SetUserVariablesRequest(SFSInstance.MySelf.GetVariables()));
        SFSInstance.Send(new ExtensionRequest("$SignUp.Submit", sfsdata));
    }
    private void Awake()
    {
        Application.runInBackground = true;

        if (SmartFoxConnection.IsInitialized)
            sfs = SmartFoxConnection.Connection;
        else
        {
            Application.LoadLevel("Login");
            return;
        }

        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
        sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
        sfs.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
        sfs.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
        sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);

        UserVariable uv = new SFSUserVariable("Ready", "NO");
        UserVariable uv2 = new SFSUserVariable("PlayerID", sfs.MySelf.PlayerId);
        List<UserVariable> lUV = new List<UserVariable>();
        lUV.Add(uv);
        lUV.Add(uv2);
        sfs.Send(new SetUserVariablesRequest(lUV));
        currentRoom = sfs.LastJoinedRoom;
    }
	private void OnExtensionResponse(BaseEvent evt) {
		string cmd = (string)evt.Params["cmd"];
		SFSObject dataObject = (SFSObject)evt.Params["params"];
		
		switch ( cmd ) {
		case "z_l":
				SFSArray userArr = (SFSArray) dataObject.GetSFSArray("user");
				SFSArray horsesArr = (SFSArray) dataObject.GetSFSArray("horses");
				SFSArray brandsArr = (SFSArray) dataObject.GetSFSArray("b");
				int consecDaysLoggedIn = (int) dataObject.GetInt("consec");
				label = "Login Data Received";
				SFSObject userObj = (SFSObject) userArr.GetSFSObject(0);
				BrandLibrary.REF.initFromSmartfox(brandsArr);
				this.onLoggedIn(userObj,horsesArr);
				Debug.Log ("Got User Object: "+userObj+" horses object: "+horsesArr.Size());
			break;
		case "p":
				float timeDiff = Time.time-_outTime;
				int tInt = Convert.ToInt32(timeDiff*1000);
				UserVariable u = new SFSUserVariable("ping",tInt);
				List<UserVariable> ul = new List<UserVariable>();
				ul.Add(u);
				this.sfs.Send(new SetUserVariablesRequest(ul));
			break;
		case "rs":
				if(RaceTrack.REF!=null) {
					RaceTrack.REF.startRace();
				}
			break;
		case "b":
			if(dataObject.ContainsKey("f")) {
				if(RaceTrack.REF!=null) {
					// Bounced race packet data.
					RaceTrack.REF.handleRacePositionsBroadcast(dataObject);
				}
			}
			break;

		} 
		
	}
	public void setMyHorseUserVar(string aHorse) {
		UserVariable r = new SFSUserVariable("h",aHorse);
		List<UserVariable> rl = new List<UserVariable>();
		rl.Add(r);
		sfs.Send(new SetUserVariablesRequest(rl));
	}
	public void setMyName(string aName) {
		UserVariable u = new SFSUserVariable("n",aName);
		List<UserVariable> l = new List<UserVariable>();
		l.Add(u);
		sfs.Send(new SetUserVariablesRequest(l));
	}
Beispiel #11
0
    public void Ready()
    {
        UserVariable uv = new SFSUserVariable("Ready", "YES");
        List<UserVariable> lUV = new List<UserVariable>();
        lUV.Add(uv);
        sfs.Send(new SetUserVariablesRequest(lUV));

        RoomVariable rv = new SFSRoomVariable("ReadyCount", int.Parse(sfs.LastJoinedRoom.GetVariable("ReadyCount").Value.ToString()) + 1);
        List<RoomVariable> lRV = new List<RoomVariable>();
        lRV.Add(rv);
        sfs.Send(new SetRoomVariablesRequest(lRV));

        ISFSObject isfsO = new SFSObject();
        isfsO.PutInt("Sender",sfs.MySelf.PlayerId);
        sfs.Send(new PublicMessageRequest("PlayerReady",isfsO,sfs.LastJoinedRoom));

        sfs.Send(new ExtensionRequest(ConfigRequestCmd.cmd_playerready, isfsO, sfs.LastJoinedRoom));
    }