Ejemplo n.º 1
0
        public void ServerCrown(byte pid)
        {
            if (!Server.IsHost)
            {
                return;
            }

            PlayerInfo pinfo = Server.PlayerInfos.Values[Server.PlayerInfos.IdsToIndices[pid]];

            // verify this pid exists
            if (Server.PlayerInfos.Length <= pid)
            {
                return; // can't exist
            }
            if (!pinfo.Active)
            {
                return; // not active
            }
            LobbyCrownId = pid;

            // send a message to all players
            Sent send = Server.GetReliableAllSend(3);

            Bytes.WriteUShort(send.Data, EventCrowned, send.Length); send.Length += 2;
            send.Data[send.Length] = pid; send.Length++;

            if (CrownedCallback != null)
            {
                CrownedCallback(pinfo);
            }
        }
Ejemplo n.º 2
0
 public void WriteGhostSecond(Sent sent)
 {
     Packer.PackFull(sent,
                     TempWriteHistory.Shots[TempWriteIndex],
                     TempWriteHistory.StaticData,
                     PackInfo);
 }
Ejemplo n.º 3
0
        // client input
        public void WriteInput(T t)
        {
            if (ClientInputCount == ClientInputs.Length)
            {
                // must resize
                ClientInputs = ResizeStructs(ClientInputs, ClientInputs.Length * 2,
                                             ClientInputStart, ClientInputCount);
                ClientInputTimestamps = ResizeStructs(ClientInputTimestamps, ClientInputTimestamps.Length * 2,
                                                      ClientInputStart, ClientInputCount);
                ClientInputTickMS = ResizeStructs(ClientInputTickMS, ClientInputTickMS.Length * 2,
                                                  ClientInputStart, ClientInputCount);
                ClientInputStart = 0;
            }

            int index = ClientInputStart + ClientInputCount;

            if (index >= ClientInputs.Length)
            {
                index -= ClientInputs.Length;
            }
            ClientInputs[index]          = t;
            ClientInputTimestamps[index] = Snapper.ClientTime;
            ClientInputTickMS[index]     = Snapper.ClientTickMS + Snapper.ClientInputTickMSInputOffset;
            ClientInputCount++;

            int slen = WriteFixedLength;

            if (slen == -1)
            {
                slen = Packer.GetWriteLength(t);
            }
            Sent sent = Snapper.GetClientInputSent(InputIndex, slen);

            Packer.Write(t, sent);
        }
        static public void sinFunc(Point pastCoint, Point nextCoint, Sent func)
        {
            long time = nextCoint.Time;

            // Point.sent = func;

            sendTask = new Task(() => { });
            sendTask.Start();
            if (time < passingTimeLimit)
            {
                passingValue = passingConstValue;
            }
            else
            {
                passingValue = time / 50;
            }

            int delay = (int)(time / passingValue * 9 / 10);

            for (int i = 0; i <= passingValue; i++)
            {
                Point temp = new Point(
                    PassingAlgoritmData(pastCoint.CanA, nextCoint.CanA, i),
                    PassingAlgoritmData(pastCoint.CanB, nextCoint.CanB, i),
                    PassingAlgoritmData(pastCoint.CanC, nextCoint.CanC, i),
                    PassingAlgoritmData(pastCoint.CanD, nextCoint.CanD, i),
                    PassingAlgoritmData(pastCoint.CanE, nextCoint.CanE, i),
                    PassingAlgoritmData(pastCoint.CanF, nextCoint.CanF, i)
                    );
                func(temp);
                Thread.Sleep(delay);
            }
        }
Ejemplo n.º 5
0
        public float TrainOne(Sent sent)
        {
            G.Need = true;
            var c = new ArcStandardConfig(sent, false, _rngChoice);

            GetTokenRepr(sent, true);
            var losses = 0f;

            while (!c.IsTerminal())
            {
                var oracle = c.GetOracle(_conf.OraType, out float[] target, out string slabel);
                GetTrans(c, out Tensor op, out Tensor label);
                G.SoftmaxWithCrossEntropy(op, target, out float loss);
                losses += loss;
                if (slabel != null)
                {
                    // in mapping 0 is unk, 1 is root
                    var labelid = _train.DepLabel[slabel] - 1;
                    G.SoftmaxWithCrossEntropy(label, labelid, out loss);
                    losses += loss;
                }

                c.Apply(oracle, slabel);
            }
            G.Backward();
            _opt.Update(FixedParams);
            _opt.Update(VariedParams);
            VariedParams.Clear();
            G.Clear();
            return(losses / sent.Count);
        }
Ejemplo n.º 6
0
        public void ServerSendChat(string msg)
        {
            if (!Server.IsHost)
            {
                throw new Exception("Tried to send host chat as client");
            }

            // increment sendkey
            if (SendKey == byte.MaxValue)
            {
                SendKey = 0;
            }
            else
            {
                SendKey++;
            }

            int  len  = Bytes.GetStringLength(msg);
            Sent send = Server.GetReliableAllSend(4 + len);

            Bytes.WriteUShort(send.Data, EventChatMessage, send.Length); send.Length += 2;
            send.Data[send.Length] = SendKey; send.Length++;
            send.Data[send.Length] = Server.OurPlayerId; send.Length++;
            Bytes.WriteString(send.Data, msg, send.Length); send.Length += len;

            // bubble the message up to our controller
            if (ChatCallback != null)
            {
                ChatCallback(Server.PlayerInfos.Values[Server.PlayerInfos.IdsToIndices[Server.OurPlayerId]], msg);
            }
        }
Ejemplo n.º 7
0
 public void Write(InputBasic2d from, Sent sent)
 {
     sent.WriteFloat(from.Vertical);
     sent.WriteFloat(from.Horizontal);
     sent.WriteFloat(from.Rotation);
     sent.WriteByte(from.Inputs);
 }
Ejemplo n.º 8
0
        public void PredictOne(Sent sent)
        {
            G.Need = false;

            var c = new ArcStandardConfig(sent, false, null);

            GetTokenRepr(sent, false);
            while (!c.IsTerminal())
            {
                GetTrans(c, out Tensor op, out Tensor label);

                // in labelid 0 is root
                // in mapping 1 is root, 0 is always unk
                var labelid  = label.W.MaxIndex();
                var plabel   = _train.DepLabel[labelid + 1];
                var scores   = op.W.Storage;
                var optScore = float.NegativeInfinity;
                var optTrans = ArcStandardConfig.Op.shift;

                for (var j = 0; j < 3; ++j)
                {
                    if (scores[j] > optScore && c.CanApply((ArcStandardConfig.Op)j, plabel))
                    {
                        optScore = scores[j];
                        optTrans = (ArcStandardConfig.Op)j;
                    }
                }
                c.Apply(optTrans, plabel);
            }
        }
Ejemplo n.º 9
0
        private void CendCompleted(object sender, SocketAsyncEventArgs args)
        {
            if (args.SocketError == SocketError.Success && args.BytesTransferred > 0)
            {
                byte[] keyBytes = new byte[16];
                Array.Copy(args.Buffer, 0, keyBytes, 0, 16);
                Guid key = new Guid(keyBytes);

                byte[] lenghtBytes = new byte[4];
                Array.Copy(args.Buffer, 16, lenghtBytes, 0, 4);
                int length = BitConverter.ToInt32(lenghtBytes);

                byte[] msgBytes = new byte[length];
                Array.Copy(args.Buffer, 20, msgBytes, 0, args.BytesTransferred - 20);

                SocketMessage msg = new SocketMessage {
                    Key = key, Body = msgBytes, Length = length
                };

                if (Sent != null)
                {
                    Sent.Invoke(this, _client, msg);
                }
            }
            else
            {
                Stop();
            }
        }
Ejemplo n.º 10
0
        public void PackDelta(Sent sent, NentBasic2d obj, PackInfoBasic2d packinfo)
        {
            sent.WriteByte(packinfo.DeltaFlag);
            if ((packinfo.DeltaFlag & DELTA_FLAG_X) != 0)
            {
                sent.WriteFloat(obj.X);
            }

            if ((packinfo.DeltaFlag & DELTA_FLAG_Y) != 0)
            {
                sent.WriteFloat(obj.Y);
            }

            if ((packinfo.DeltaFlag & DELTA_FLAG_ROT) != 0)
            {
                sent.WriteFloat(obj.Rot);
            }

            if ((packinfo.DeltaFlag & DELTA_FLAG_XVEL) != 0)
            {
                sent.WriteFloat(obj.XVel);
            }

            if ((packinfo.DeltaFlag & DELTA_FLAG_YVEL) != 0)
            {
                sent.WriteFloat(obj.YVel);
            }

            if ((packinfo.DeltaFlag & DELTA_FLAG_FREE1) != 0)
            {
                sent.WriteFloat(obj.Free1);
            }
        }
        //для записи точек
        static public void sinFunc(Point pastCoint, Point nextCoint, Sent funcData, Sent funcTime)
        {
            sendTask = new Task(() => { });
            sendTask.Start();
            if (nextCoint.Time < passingTimeLimit)
            {
                passingValue = passingConstValue;
            }
            else
            {
                passingValue = nextCoint.Time / 50;
            }

            int delay = (int)((nextCoint.Time / passingValue) * 92 / 100);

            for (int i = 0; i <= passingValue; i++)
            {
                Point point = new Point(
                    oneSinFuncData(pastCoint.CanA, nextCoint.CanA, i),
                    oneSinFuncData(pastCoint.CanB, nextCoint.CanB, i),
                    oneSinFuncData(pastCoint.CanC, nextCoint.CanC, i),
                    oneSinFuncData(pastCoint.CanD, nextCoint.CanD, i),
                    oneSinFuncData(pastCoint.CanE, nextCoint.CanE, i),
                    oneSinFuncData(pastCoint.CanF, nextCoint.CanF, i),
                    0);

                // funcData(point.ToString());
                //funcTime(delay.ToString());
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="et"></param>
        /// <param name="arg"></param>
        private void CompleteProcessing(EventEntry entry)
        {
            switch (entry.Type)
            {
            case EventType.IsConnecting:
                IsConnecting?.Invoke(this, (int)entry.Argument);
                break;

            case EventType.IsListening:
                IsListening?.Invoke(this, EventArgs.Empty);
                break;

            case EventType.Connected:
                Connected?.Invoke(this, EventArgs.Empty);
                break;

            case EventType.Disconnected:
                Disconnected?.Invoke(this, EventArgs.Empty);
                break;

            case EventType.Sent:
                Sent?.Invoke(this, ( Message )entry.Argument);
                break;

            case EventType.Received:
                Received?.Invoke(this, ( Message )entry.Argument);
                break;

            case EventType.T3Timeout:
                T3Timeout?.Invoke(this, ( Message )entry.Argument);
                break;

            default: break;
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (Camera != null)
            {
                Camera.Dispose();
                Camera = null;
            }

            if (Gallery != null)
            {
                Gallery.Dispose();
                Gallery = null;
            }

            if (Sent != null)
            {
                Sent.Dispose();
                Sent = null;
            }

            if (Test != null)
            {
                Test.Dispose();
                Test = null;
            }
        }
Ejemplo n.º 14
0
        public void Send()
        {
            var message = new TextMessage(InputBox.Text, DateTime.Now, UserService.LoggedUser);

            Sent?.Invoke(this, message);
            InputBox.Text = "";
        }
        static private void oneSinFunc(int pastCoint, int nextCoint, Sent func, char numCanal, int cycle)
        {
            double a     = (nextCoint - pastCoint) / 2;
            int    coint = Convert.ToInt32(a * (-Math.Cos(3.14 / Convert.ToDouble(passingValue) * Convert.ToDouble(cycle)) + 1) + pastCoint);

            sendTask.Wait();
            //sendTask = Task.Run(() => func(numCanal + coint.ToString() + 'z'));
        }
Ejemplo n.º 16
0
        public void SendConsole(string message)
        {
            Console.WriteLine($"Sending console {message}");

            Sent?.Invoke();

            SendError?.Invoke(this, new SendErrorEventArgs("brak polaczenia"));
        }
Ejemplo n.º 17
0
 public void SendAll()
 {
     while (_queue.Count > 0)
     {
         var email = _queue.Dequeue();
         Sent?.Invoke(email);
     }
 }
Ejemplo n.º 18
0
        public JObject ToJson(ProtocolSettings protocolSettings)
        {
            JObject json = new JObject();

            json["sent"]     = Sent.Select(p => p.ToJson(protocolSettings)).ToArray();
            json["received"] = Received.Select(p => p.ToJson(protocolSettings)).ToArray();
            json["address"]  = UserScriptHash.ToAddress(protocolSettings.AddressVersion);
            return(json);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Raises the Sent event.
        /// </summary>
        internal static void OnSent(IEmailQueueItem item, MailMessage message)
        {
            if (!item.IsNew)
            {
                Database.Delete(item);
            }

            Sent?.Invoke(item, new EventArgs <MailMessage>(message));
        }
Ejemplo n.º 20
0
 public ArcStandardConfig(Sent sent, bool reserve, RandomNumberGenerator rng)
 {
     _sent = sent;
     Stack = new ParseForest();
     Stack.PushBack(Entry.Root());
     Buffer = new ParseForest(sent, reserve);
     Apply(Op.shift, null);
     _rng = rng;
 }
Ejemplo n.º 21
0
        public JObject ToJson()
        {
            JObject json = new JObject();

            json["sent"]     = Sent.Select(p => p.ToJson()).ToArray();
            json["received"] = Received.Select(p => p.ToJson()).ToArray();
            json["address"]  = UserScriptHash.ToAddress();
            return(json);
        }
    public static void Main()
    {
        var a = new Sent {
            Address = "04004C", Data = "55AA55"
        };
        var b = new Sent {
            Address = "04004C", Data = "55AA55"
        };

        Console.WriteLine(a.Equals(b));     // True with use of an AOP, False with no AOP

        var sent = new List <Sent>()
        {
            new Sent {
                Address = "04004C", Data = "55AA55"
            },
            new Sent {
                Address = "040004", Data = "0720"
            },
            new Sent {
                Address = "040037", Data = "31"
            },
            new Sent {
                Address = "04004A", Data = "FFFF"
            }
        };

        var res = new List <Result>()
        {
            new Result {
                AddressOK = "04004C", DataOK = "55AA55"
            },
            new Result {
                AddressOK = "040004", DataOK = "0721"
            },
            new Result {
                AddressOK = "040038 ", DataOK = "31"
            },
            new Result {
                AddressOK = "04004A", DataOK = "FFFF"
            }
        };


        var diff =
            sent.Except(
                res.Select(r => new Sent {
            Address = r.AddressOK, Data = r.DataOK
        })
                );

        foreach (var item in diff)
        {
            Console.WriteLine("{0} {1}", item.Address, item.Data);
        }
    }
Ejemplo n.º 23
0
        private void Send(string messageType, FIXMessageWriter message, long seqNum)
        {
            message.Prepare(Configuration.Version, messageType, seqNum, Clock.Time, Configuration.Sender, Configuration.Target);

            Channel.Write(message);

            State.OutboundTimestamp = Clock.Time;

            Sent?.Invoke(this, message);
        }
Ejemplo n.º 24
0
        public void RaiseOutgoing(ISendable target, IMessage message)
        {
            if (target == null || message == null)
            {
                return;
            }

            Log.Trace($"[OUT ({message.Attachments?.Count})] {message?.Text}");
            Sent?.Invoke(this, new MessageSentEventArgs(target, message));
        }
Ejemplo n.º 25
0
 public void Write(byte[] data, bool notifyOnSuccess = true)
 {
     try
     {
         networkStream.BeginWrite(data, 0, data.Length, EndWrite, new WriteIOState(data, notifyOnSuccess));
     }
     catch (Exception ex)
     {
         Sent?.Invoke(this, new SentEventArgs(ex, this, data));
     }
 }
Ejemplo n.º 26
0
        /// <summary>
        ///		Start an offset update if enough time has passed.
        /// </summary>
        /// <param name="server">The server peer.</param>
        public void Update()
        {
            if (!_pingTimer.TryCycle())
            {
                return;
            }

            _server.Send(PingMessage.Now);

            Sent?.Invoke();
        }
Ejemplo n.º 27
0
 public void RaiseOutgoing(ISendable target, IMessage message)
 {
     _outgoingStopwatch.Start();
     Sent?.Invoke(this, new MessageSentEventArgs(target, message));
     _outgoingStopwatch.Stop();
     if (_outgoingStopwatch.ElapsedMilliseconds > 100)
     {
         Debug.WriteLine($"Outgoing message bus took {_incomingStopwatch.ElapsedMilliseconds}ms!");
     }
     _outgoingStopwatch.Reset();
 }
Ejemplo n.º 28
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Sent.GetHashCode();
         hashCode = (hashCode * 397) ^ (Id != null ? Id.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Message != null ? Message.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ErrorMessage != null ? ErrorMessage.GetHashCode() : 0);
         return(hashCode);
     }
 }
Ejemplo n.º 29
0
 public void PackFull(Sent sent, NentBasic2d obj, NentStaticBasic2d stat, PackInfoBasic2d packinfo)
 {
     sent.WriteByte(stat.Id1);
     sent.WriteUShort(stat.Id2);
     sent.WriteFloat(obj.X);
     sent.WriteFloat(obj.Y);
     sent.WriteFloat(obj.Rot);
     sent.WriteFloat(obj.XVel);
     sent.WriteFloat(obj.YVel);
     sent.WriteFloat(obj.Free1);
 }
Ejemplo n.º 30
0
 public bool DeleteMessageSent(int index)
 {
     if (index < Sent.Count)
     {
         Sent.RemoveAt(index);
         return(true);
     }
     else
     {
         return(false);
     }
 }