public RPCEvent(INetClient client, NetworkEvent netEvent, BSONObject bson, String methodName) { this._client = client; this._netEvent = netEvent; this._bson = bson; this._methodName = methodName; }
private void ConnectCallback(IAsyncResult ar) { try { Socket tClient = (Socket)ar.AsyncState; stateObj.workSocket = tClient; BSONObject request = new BSONObject(); request["msg"] = "auth"; request["note"] = "(none)"; request["mID"] = HardwareID.GetHwid(); byte[] requestData = SimpleBSON.Dump(request); tClient.BeginSend(requestData, 0, requestData.Length, SocketFlags.None, new AsyncCallback(SendCallback), stateObj); tClient.BeginReceive(stateObj.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), stateObj); } catch { } }
private void readSocket() { //Console.WriteLine(" - Try to read!"); if (!socket_ready) { return; } if (net_stream.DataAvailable && net_stream.CanRead) { //Debug.Log("Read Socket"); try { // decrypt ? BSONObject obj = null; obj = SimpleBSON.Load(ByteStreamParser.parseStream(net_stream)); IClientCmd clientCmd = cmdMgr.decodeBSON(obj); if (clientCmd != null) { this.observer.addClientCmd(clientCmd); } else { Debug.LogError("ClientCmd not parsed !"); } } catch (Exception e) { Debug.LogError("Exception:" + e); } } }
private void writeSocket() { if (!socket_ready) { return; } Queue <IServerCmd> srvCmdList = this.cmdMgr.getServerCmds(); if (srvCmdList.Count <= 0) { return; } //Debug.Log("Write Socket"); for (var i = 0; i < srvCmdList.Count; i++) { IServerCmd cmd = srvCmdList.Dequeue(); BSONObject obj = cmd.encode(); byte[] raw = SimpleBSON.Dump(obj); socket_writer.Write(raw, 0, raw.Length); socket_writer.Flush(); //Debug.Log (" - Command written!"); } }
public override void SendUpdate(BSONObject bsonObj, INetObjectViewer viewer) { if (this.attached == null) { base.SendUpdate(bsonObj, viewer); } }
public override void SoundPlayMsg(icSound sound) { BSONObject b = new BSONObject(); b["id"] = sound.GetId(); bsonChildren["play"].Add(b); }
public override void ReceiveUpdate(BSONObject bsonObj) { bool changed = false; if (!bsonObj.ContainsKey("trunks")) { return; } BSONArray trunks = bsonObj["trunks"].ArrayValue; foreach (BSONObject obj in trunks) { Guid id = obj["id"]; TrunkPiece piece = this.trunkPieces.FirstOrDefault(p => p.ID == id); if (piece != null && (piece.Position != obj["pos"] || piece.Rotation != obj["rot"])) { piece.Position = obj["pos"]; piece.Rotation = obj["rot"]; piece.Velocity = obj["v"]; piece.LastUpdateTime = TimeUtil.Seconds; changed = true; } } if (changed) { if (this.UpRooted) { this.Position = this.trunkPieces.First().Position; } this.lastKeyframeTime = bsonObj["time"]; this.LastUpdateTime = TimeUtil.Seconds; } }
public override void SendInitialState(BSONObject bsonObj, INetObjectViewer viewer) { base.SendInitialState(bsonObj, viewer); // if we have trunk pieces, send those if (this.trunkPieces.Count > 0) { BSONArray trunkInfo = BSONArray.New; foreach (var trunkPiece in this.trunkPieces) { trunkInfo.Add(trunkPiece.ToInitialBson()); } bsonObj["trunks"] = trunkInfo; } if (this.Controller != null && this.Controller is INetObject) { bsonObj["controller"] = ((INetObject)this.Controller).ID; } if (this.stumpHealth <= 0f) // trunk pieces have their own grounders { bsonObj["noGround"] = true; } bsonObj["mult"] = this.resourceMultiplier; }
public void ReceiveEvent(INetClient client, NetworkEvent netEvent, BSONObject bson) { switch (netEvent) { case NetworkEvent.ClientUpdate: if (!createFromNetworkEvent(client, netEvent, bson).isCanceled) { NetObjectManager.Obj.UpdateObjects(bson); } break; case NetworkEvent.RPC: if (!createEventFromNetworkRPCEvent(client, netEvent, bson).isCanceled) { RPCManager.HandleReceiveRPC(client, bson); } break; case NetworkEvent.RPCResponse: if (!createFromNetworkResponseEvent(client, netEvent, bson).isCanceled) { RPCManager.HandleQueryResponse(bson); } break; } }
/// <summary> /// Gets the versions. /// </summary> /// <returns> /// Returns an enumerable with the MongoDb versions. /// </returns> /// <exception cref="NAMEException">Thrown when an unexpected exception happens.</exception> public override async Task <IEnumerable <DependencyVersion> > GetVersions() { var versions = new List <DependencyVersion>(); if (!this.connectionStringProvider.TryGetConnectionString(out string connectionString)) { throw new ConnectionStringNotFoundException(this.connectionStringProvider.ToString()); } var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString); byte[] message = this.CreateServerStatusMessagePayload(connectionStringBuilder); foreach (var mongoEndpoint in connectionStringBuilder.Servers) { using (var client = await this.OpenTcpClient(mongoEndpoint.Host, mongoEndpoint.Port, SupportedDependencies.MongoDb.ToString())) { await client.GetStream().WriteAsync(message, 0, message.Length, default(CancellationToken)).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); BSONObject obj = ExtractServerStatusFromResponse(client); versions.Add(DependencyVersionParser.Parse(obj["version"].stringValue, false)); } } return(versions); }
public void ReadSingleObject() { byte[] data = MiscellaneousUtils.HexToBytes("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00"); BSONObject obj = SimpleBSON.Load(data); Assert.AreEqual(obj ["Blah"].int32Value, 1); }
override public BSONObject encode() { BSONObject obj = new BSONObject(); obj ["id"] = this.id; obj ["meta"] = this.GetType().Name; return(obj); }
public override void SoundPlayRateMsg(icSound sound) { BSONObject b = new BSONObject(); b["id"] = sound.GetId(); b["speed"] = sound.PlayRate; bsonChildren["playrate"].Add(b); }
public override void SoundPositionMsg(icSound sound) { BSONObject b = new BSONObject(); b["id"] = sound.GetId(); b["position"] = WorldToBellowsPosition(sound.GetWorldPosition()); bsonChildren["move"].Add(b); }
public override void SoundVolumeMsg(icSound sound) { BSONObject b = new BSONObject(); b["id"] = sound.GetId(); b["volume"] = sound.Volume; bsonChildren["volume"].Add(b); }
public override void SoundSeekMsg(icSound sound, int milliseconds) { BSONObject b = new BSONObject(); b["id"] = sound.GetId(); b["t"] = milliseconds; bsonChildren["time"].Add(b); }
public override void ReceiveUpdate(BSONObject bsonObj) { base.ReceiveUpdate(bsonObj); if (this.Position.y <= 0) { this.Destroy(); } }
public override void SendUpdate(BSONObject bsonObj, INetObjectViewer viewer) { base.SendUpdate(bsonObj, viewer); var cage = BSONObject.New; cage["pos"] = new Vector3(0f, this.cagePos, 0f); cage["v"] = new Vector3(0f, this.cageVelocity, 0f); bsonObj["cage"] = cage; }
public override void SendInitialState(BSONObject bsonObj, INetObjectViewer viewer) { base.SendInitialState(bsonObj, viewer); bsonObj["pos"] = this.Position; bsonObj["force"] = this.CastForce; if (this.Controller != null && this.Controller is INetObject) { bsonObj["controller"] = ((INetObject)this.Controller).ID; } }
public void WriteSingleObject() { BSONObject obj = new BSONObject(); obj ["Blah"] = 1; string bson = MiscellaneousUtils.BytesToHex(SimpleBSON.Dump(obj)); Assert.AreEqual("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00", bson); }
public void ReadArray() { byte[] data = MiscellaneousUtils.HexToBytes("31-00-00-00-04-42-53-4f-4e-00-26-00-00-00-02-30-00-08-00-00-00-61-77-65-73-6f-6d-65-00-01-31-00-33-33-33-33-33-33-14-40-10-32-00-c2-07-00-00-00-00"); BSONObject obj = SimpleBSON.Load(data); Assert.IsTrue(obj ["BSON"] is BSONArray); Assert.AreEqual(obj ["BSON"][0].stringValue, "awesome"); Assert.AreEqual(obj ["BSON"][1].doubleValue, 5.05); Assert.AreEqual(obj ["BSON"][2].int32Value, 1986); }
// ----- static encode/decode ----- public static byte[] encode(BSONObject o) { BSONEncoder e = _staticEncoder.get(); try { return e.encode(o); } finally { e.done(); } }
void Awake() { // Set up BSON objects before script Start() bsonRoot = new BSONObject(); bsonGlobals = new BSONObject(); bsonChildren["load"] = new BSONArray(); bsonChildren["play"] = new BSONArray(); bsonChildren["move"] = new BSONArray(); bsonChildren["volume"] = new BSONArray(); bsonChildren["playrate"] = new BSONArray(); bsonChildren["time"] = new BSONArray(); }
public override void SendInitialState(BSONObject bsonObj, INetObjectViewer viewer) { base.SendInitialState(bsonObj, viewer); if (this.attached != null) { bsonObj["attached"] = this.attached.ToBson(); } bsonObj["v"] = this.Velocity; if (this.Controller != null && this.Controller is INetObject) { bsonObj["controller"] = ((INetObject)this.Controller).ID; } }
public void WriteArray() { byte[] data = MiscellaneousUtils.HexToBytes("31-00-00-00-04-42-53-4f-4e-00-26-00-00-00-02-30-00-08-00-00-00-61-77-65-73-6f-6d-65-00-01-31-00-33-33-33-33-33-33-14-40-10-32-00-c2-07-00-00-00-00"); BSONObject obj = new BSONObject(); obj ["BSON"] = new BSONArray(); obj ["BSON"].Add("awesome"); obj ["BSON"].Add(5.05); obj ["BSON"].Add(1986); byte[] target = SimpleBSON.Dump(obj); Assert.IsTrue(MiscellaneousUtils.ByteArrayCompare(target, data) == 0); }
public static bool Prefix(ref string methodname, ref BSONObject bson, object __result) { RpcInvokeEvent rie = new RpcInvokeEvent(methodname, bson); IEvent rieEvent = rie; EventManager.CallEvent(ref rieEvent); if (rie.IsCancelled()) { __result = null; return(false); } return(true); }
public override void ReceiveUpdate(BSONObject bsonObj) { base.ReceiveUpdate(bsonObj); if (bsonObj.ContainsKey("cage")) { var cagebson = bsonObj["cage"].ObjectValue; this.cagePos = cagebson["pos"].Vector3Value.y; this.cageVelocity = cagebson["v"].Vector3Value.y; } if (bsonObj.ContainsKey("stop")) { this.cageVelocity = 0f; this.SetAnimatedState("dir", 0f); } }
private byte[] CreateServerStatusMessagePayload(MongoConnectionStringBuilder connectionStringBuilder) { byte[] message; int commandLength; //Write the message first because we need the it's length using (var commandMemoryStream = new MemoryStream()) using (var commandWriter = new BinaryWriter(commandMemoryStream, new UTF8Encoding(), true)) { //Query options commandWriter.Write(0); //Collection name commandWriter.Write($"{connectionStringBuilder.Database}.$cmd".ToArray()); //cstring's require a \x00 at the end. commandWriter.Write('\x00'); //Number to skip commandWriter.Write(0); //Number to return commandWriter.Write(-1); var commandBSON = new BSONObject { ["serverStatus"] = 1.0 }; commandWriter.Write(SimpleBSON.Dump(commandBSON)); commandWriter.Flush(); commandLength = (int)commandMemoryStream.Length; message = new byte[16 + commandLength]; Array.Copy(commandMemoryStream.ToArray(), 0, message, 16, commandLength); } using (var messageMemoryStream = new MemoryStream(message)) using (var completeMessageWriter = new BinaryWriter(messageMemoryStream, new UTF8Encoding(), true)) { //Message length completeMessageWriter.Write(16 + commandLength); //Request Id completeMessageWriter.Write(0); //Response To completeMessageWriter.Write(0); //Operation Code completeMessageWriter.Write(2004); completeMessageWriter.Flush(); } return(message); }
public override void ReceiveUpdate(BSONObject bsonObj) { // Store the received position if valid. if (bsonObj.TryGetValue("pos", out var pos) && Vector3.IsValid(pos.Vector3Value)) { this.Position = pos; } // If the Lure has no controller or has descended below the world, destroy it. bsonObj.TryGetValue("controlled", out var controlled); if ((this.Position.y < -30.0f) || !controlled) { this.Destroy(); } base.ReceiveUpdate(bsonObj); }
protected override void SoundLoadMsg(icSound sound) { BSONObject b = new BSONObject(); b["id"] = sound.GetId(); b["streaming"] = new BSONValue(sound.IsStreaming()); b["looping"] = new BSONValue(sound.IsLooping()); b["videosync"] = new BSONValue(sound.IsVideoSync()); b["permanent"] = new BSONValue(true); b["path"] = sound.GetFilePath(); b["speed"] = sound.PlayRate; b["volume"] = sound.Volume; b["position"] = WorldToBellowsPosition(sound.GetWorldPosition()); bsonChildren["load"].Add(b); }