Example #1
0
        private Action <object[]> ServerAction(Action <object[]> real, Type[] types, bool useContext = true)
        {
            byte id = actionId++;

            useContextMap[id] = useContext;
            Action <object[], bool> action = (param, isReceiving) => {
                byte _id = id;
                if (IsServer)
                {
                    real.Invoke(param);
                }

                if (IsClient)
                {
                    RFCExecute msg = new RFCExecute();
                    msg.FunctionId = _id;
                    var buff        = new DataBuffer();
                    var _useContext = useContextMap[msg.FunctionId];
                    WriteModelsToBuffer(buff, param, _useContext);
                    msg.FunctionParameters = buff.ToBytes();
                    ChRFCExecute.Send(new OutgoingMessage <RFCExecute>(msg));
                }
            };

            svActionMap[id] = (obj, rec) => action(obj, rec);
            svTypeMap[id]   = types;

            return((param) => action(param, false));
        }
Example #2
0
        private void OnSetNetTime(IncomingMessage <P_SetNetTime> obj)
        {
            var svNetTime = obj.Data.NetTime;
            var diff      = pingTimer.Elapsed.TotalSeconds;

            svNetTime += diff / 2d;

            offset = svNetTime - clientTimer.Elapsed.TotalSeconds;

            ScheduleEvent(250, () => {
                pingTimer.Reset();
                pingTimer.Start();
                P_GetNetTime msg = new P_GetNetTime();
                ChGetNetTime.Send(new OutgoingMessage <P_GetNetTime>(msg));
            });
        }
Example #3
0
        private void OnGetNetTime(IncomingMessage <P_GetNetTime> obj)
        {
            P_SetNetTime reply = new P_SetNetTime();

            reply.NetTime = GetNetTime();

            ChSetNetTime.Send(new OutgoingMessage <P_SetNetTime>(reply, obj.Sender));
        }
Example #4
0
        private void OnPingReceived(IncomingMessage <P_Ping> obj)
        {
            if (IsServer)
            {
                var timer = GetTimer(obj.Sender);
                obj.Sender.SetLocal <double>(LatencyKey, timer.Elapsed.TotalSeconds);
                timer.Stop();
                timer.Reset();

                var user = obj.Sender;
                ScheduleEvent(new TimeSpan(0, 0, 0, 0, PingSendDelay), () => {
                    P_Ping ping = new P_Ping();
                    ChPing.Send(new OutgoingMessage <P_Ping>(ping, user));
                    timer.Start();
                });
            }

            if (IsClient)
            {
                ChPing.Send(new OutgoingMessage <P_Ping>(obj.Data));
            }
        }
Example #5
0
 public void Send(T data)
 {
     Source.Send(new OutgoingMessage <PassthroughPacket <T> >(new PassthroughPacket <T>(data)));
 }