private void StationListener_OnMsg(JObject obj) { if (obj["status"].ToString() != "success") { return; } var resp = obj["response"]; switch ((string)obj["action"]) { case "sendServerTime": Car.DeltaTime = (long)resp["time"] - DateTime.UtcNow.ToTimestamp(); break; case "sendRoomNumberList": foreach (JObject car in (JArray)resp) { var c = new Car(car); lock (cars) cars.Add(c); OnNewCar?.Invoke(c); } break; } }
private void StationListener_OnMsg(JObject obj) { this.Log(LoggerLevel.Info, obj); if (obj["status"].ToString() != "success" || obj["action"].ToString() != "sendRoomNumberList") { return; } foreach (JObject car in (JArray)obj["response"]) { this.Log(LoggerLevel.Info, car); var c = new Car(car); lock (cars) cars.Add(c); OnNewCar?.Invoke(c); } }
public async Task <bool> OnMessage(HandlerArgs args) { var message = args.message; if (message == "m" || message == "M") { if (LastCar.TryGetValue(args.Sender.FromQQ, out int lc)) { lock (sekaicars) sekaicars = sekaicars.Where(c => c.index != lc).ToList(); } return(true); } int split, car; if (IsIgnore(args.Sender)) { return(false); } if (message.Length < 5) { return(false); } for (int i = 0; i < 5; ++i) { if (!IsNumeric(message[i])) { return(false); } } split = message.Length > 5 && IsNumeric(message[5]) ? 6 : 5; if (message.Length > split && IsNumeric(message[split])) { return(false); } car = int.Parse(message.Substring(0, split)); LastCar[args.Sender.FromQQ] = car; string raw_message = car.ToString("d5") + " " + message.Substring(split); // ignore non-text messages raw_message = codereg.Replace(raw_message, _ => ""); switch (Configuration.GetConfig <CarTypeConfig>()[args.Sender.FromGroup]) { case CarType.Bandori: var ignore = CheckIgnored(car, message.Substring(split)); if (ignore != null) { if (ignore != "") { await args.Callback(ignore); } break; } JObject res = await Utils.GetHttp($"http://api.bandoristation.com/?function=submit_room_number&number={car}&source={source}&token={token}&raw_message={raw_message}&user_id={args.Sender.FromQQ}"); if (res == null) { await args.Callback($"无法连接到bandoristation.com"); } else if (res["status"].ToString() != "success") { await args.Callback($"上传车牌时发生错误: {res["response"]}"); } return(true); case CarType.Sekai: if (CheckIgnored(car, message.Substring(split)) == "") { break; } if (car == 114514 || car == 11451 || car == 19198) { break; } var caro = new Car { index = car, rawmessage = raw_message, time = DateTime.UtcNow }; lock (sekaicars) sekaicars.Add(caro); OnNewCar?.Invoke(caro); return(true); } return(false); }
public GameObject Spawn(tk.JsonTcpClient client) { if (carPrefab == null) { Debug.LogError("No carPrefab set in CarSpawner!"); return(null); } // Create a car object, and also hook up all the connections // to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; if (go == null) { Debug.LogError("CarSpawner failed to instantiate prefab!"); return(null); } cars.Add(go); (Vector3 startPos, Quaternion startRot) = GetCarStartPosRot(); go.transform.position = startPos; go.transform.rotation = startRot; go.GetComponent <Car>().SavePosRot(); UpdateSplitScreenCams(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); // CarTextFacecamera(go, cam.transform); if (TcpClientObj != null) { // without this it will not connect. TcpClientObj.SetActive(true); // now set the connection settings. TcpCarHandler carHandler = TcpClientObj.GetComponent <TcpCarHandler>(); if (carHandler != null) { carHandler.Init(client); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// // Search scene to find these. MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = null; GameObject pidPanel = getChildGameObject(canvas.gameObject, "PIDPanel"); /////////////////////////////////////////////// if (pidPanel) { pid_ui = pidPanel.GetComponent <PID_UI>(); } // set camera target follow tm // Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } // Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } // Add race status, if possible. GameObject to = getChildGameObject(go, "Timer"); if (to != null) { AddTimer(to.GetComponent <Timer>(), client); } else { Debug.LogError("failed to find Timer"); } return(go); }
public GameObject Spawn(tk.JsonTcpClient client) { if (carPrefab == null) { Debug.LogError("No carPrefab set in CarSpawner!"); return(null); } //Create a car object, and also hook up all the connections //to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; if (go == null) { Debug.LogError("CarSpawner failed to instantiate prefab!"); return(null); } cars.Add(go); Vector3 offset = Vector3.zero; //just stack more cars after the second. Not pretty. int iRow = (cars.Count - 1) / 2; offset = Vector3.forward * (-5f * iRow); if (cars.Count % 2 == 0) { offset += Vector3.left * 4.5f; } go.transform.rotation = startTm.rotation; go.transform.position = startTm.position + offset; go.GetComponent <Car>().SavePosRot(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); Camera cam = Camera.main; //Detect that we have the second car. Doesn't really handle more than 2 right now. if (cars.Count > 1) { cam = ActivateSplitScreen(); } // CarTextFacecamera(go, cam.transform); if (TcpClientObj != null) { //without this it will not connect. TcpClientObj.SetActive(true); //now set the connection settings. TcpCarHandler carHandler = TcpClientObj.GetComponent <TcpCarHandler>(); if (carHandler != null) { carHandler.Init(client); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// //Search scene to find these. CameraFollow cameraFollow = cam.transform.GetComponent <CameraFollow>(); MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = null; GameObject pidPanel = getChildGameObject(canvas.gameObject, "PIDPanel"); /////////////////////////////////////////////// if (pidPanel) { pid_ui = pidPanel.GetComponent <PID_UI>(); } //set camera target follow tm if (cameraFollow != null) { cameraFollow.target = getChildGameObject(go, "CameraFollowTm").transform; } //Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } //Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } return(go); }
public YCM() { listener = new StationListener(); listener.OnNewCar += car => OnNewCar?.Invoke(car); listener.Start(); }
public GameObject Spawn(tk.JsonTcpClient client) { if (carPrefab == null) { Debug.LogError("No carPrefab set in CarSpawner!"); return(null); } //Create a car object, and also hook up all the connections //to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; if (go == null) { Debug.LogError("CarSpawner failed to instantiate prefab!"); return(null); } cars.Add(go); Vector3 startPos = GetCarStartPos(cars.Count - 1, true); go.transform.rotation = startTm.rotation; go.transform.position = startPos; go.GetComponent <Car>().SavePosRot(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); Camera cam = Camera.main; bool bRaceActive = false; RaceManager raceMan = GameObject.FindObjectOfType <RaceManager>(); if (raceMan) { bRaceActive = raceMan.bRaceActive; } GenPathFromDriving pathGen = GameObject.FindObjectOfType <GenPathFromDriving>(); if (pathGen) { pathGen.Init(go); } //Detect that we have the second car. Doesn't really handle more than 2 right now. if (cars.Count > 1 && !bRaceActive) { cam = ActivateSplitScreen(); } // CarTextFacecamera(go, cam.transform); if (TcpClientObj != null) { //without this it will not connect. TcpClientObj.SetActive(true); //now set the connection settings. TcpCarHandler carHandler = TcpClientObj.GetComponent <TcpCarHandler>(); if (carHandler != null) { carHandler.Init(client); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// //Search scene to find these. CameraFollow cameraFollow = null; if (cam != null) { cameraFollow = cam.transform.GetComponent <CameraFollow>(); } MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = null; GameObject pidPanel = getChildGameObject(canvas.gameObject, "PIDPanel"); /////////////////////////////////////////////// if (pidPanel) { pid_ui = pidPanel.GetComponent <PID_UI>(); } //set camera target follow tm if (cameraFollow != null) { cameraFollow.target = getChildGameObject(go, "CameraFollowTm").transform; } //Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } //Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } //Add race status, if possible. if (raceMan != null) { GameObject to = getChildGameObject(go, "LapTimer"); if (to != null) { raceMan.AddLapTimer(to.GetComponent <LapTimer>(), client); } } return(go); }
public void Spawn(Vector3 offset, string host = "", string port = "") { //Create a car object, and also hook up all the connections //to various places in game that need to hook into the car. GameObject go = GameObject.Instantiate(carPrefab) as GameObject; cars.Add(go); if (cars.Count > 2) { //just stack more cars after the second. Not pretty. offset = offset + Vector3.forward * (-5f * (cars.Count - 2)); } go.transform.rotation = startTm.rotation; go.transform.position = startTm.position + offset; go.GetComponent <Car>().SavePosRot(); GameObject TcpClientObj = getChildGameObject(go, "TCPClient"); Camera cam = Camera.main; //Detect that we have the second car. Doesn't really handle more than 2 right now. if (cars.Count > 1) { if (splitScreenCamLeft != null) { splitScreenCamLeft.gameObject.SetActive(true); cam = splitScreenCamLeft; } if (splitScreenCamRight != null) { splitScreenCamRight.gameObject.SetActive(true); //would be better to render both to textures, but too much work. Transform camFollowRt = getChildGameObject(cars[0], "CameraFollowTm").transform; CameraFollow rtCameraFollow = splitScreenCamRight.transform.GetComponent <CameraFollow>(); rtCameraFollow.target = camFollowRt; } if (splitScreenPanel) { splitScreenPanel.SetActive(true); } } if (TcpClientObj != null && host != "" && port != "") { //without this it will not connect. TcpClientObj.SetActive(true); //now set the connection settings. The jsonclient will attempt to connect //later in the update loop. JsonTcpClient jsonClient = TcpClientObj.GetComponent <JsonTcpClient>(); if (jsonClient != null) { jsonClient.nnIPAddress = host; jsonClient.nnPort = int.Parse(port); } } if (OnNewCarCB != null) { OnNewCarCB.Invoke(go); } /////////////////////////////////////////////// //Search scene to find these. CameraFollow cameraFollow = cam.transform.GetComponent <CameraFollow>(); MenuHandler menuHandler = GameObject.FindObjectOfType <MenuHandler>(); Canvas canvas = GameObject.FindObjectOfType <Canvas>(); GameObject panelMenu = getChildGameObject(canvas.gameObject, "Panel Menu"); PID_UI pid_ui = getChildGameObject(canvas.gameObject, "PIDPanel").GetComponent <PID_UI>(); /////////////////////////////////////////////// //set camera target follow tm if (cameraFollow != null) { cameraFollow.target = getChildGameObject(go, "CameraFollowTm").transform; } //Set menu handler hooks if (menuHandler != null) { menuHandler.PIDContoller = getChildGameObject(go, "PIDController"); menuHandler.Logger = getChildGameObject(go, "Logger"); menuHandler.NetworkSteering = getChildGameObject(go, "TCPClient"); menuHandler.carJSControl = getChildGameObject(go, "JoyStickCarContoller"); menuHandler.trainingManager = getChildGameObject(go, "TrainingManager").GetComponent <TrainingManager>(); menuHandler.trainingManager.carObj = go; if (EnableTrainingManager) { menuHandler.trainingManager.gameObject.SetActive(true); getChildGameObject(go, "OverheadViewSphere").SetActive(true); } if (GlobalState.bAutoConnectToWebSocket && menuHandler.NetworkSteering != null) { menuHandler.NetworkSteering.SetActive(true); } if (GlobalState.bAutoHideSceneMenu && panelMenu != null) { panelMenu.SetActive(false); } } else { Debug.LogError("need menu handler"); } //Set the PID ui hooks if (pid_ui != null) { pid_ui.pid = getChildGameObject(go, "PIDController").GetComponent <PIDController>(); pid_ui.logger = getChildGameObject(go, "Logger").GetComponent <Logger>(); } else { Debug.LogError("failed to find PID_UI"); } }