コード例 #1
0
        public Peer(string name)
        {
            CanAppend        = true;
            IncomingMessages = new ConcurrentQueue <string>();
            this.Name        = name;

            protocolExample = GemClient.Profile("GemChat")
                              .CreateNetworkProtocolEvent <Package>()
                              .HandleIncoming((sender, package) =>
            {
                QueueMessage(String.Format("Server sent {0} {1}", sender.Statistics.SentBytes, package.Name));
            })
                              .GenerateSendEvent();

            onEvent = GemClient.Profile("GemChat")
                      .CreateNetworkEvent
                      .AndHandleWith(this, x => new Action <string>(x.QueueMessage));

            onCommandExecute = GemClient.Profile("GemChat")
                               .CreateNetworkEvent
                               .AndHandleWith(this, x => new Action <string>(x.ExecuteCommand));

            onEvent.Send(name + " has joined");
            messageAppender = new ParallelTaskStarter(TimeSpan.Zero);
            messageAppender.Start(DequeueIncomingMessages);
        }
コード例 #2
0
 internal static void RegisterEvent(INetworkEvent ev)
 {
     if (events == null)
     {
         events = new Dictionary <byte, INetworkEvent>();
     }
     events.Add(ev.Code, ev);
 }
コード例 #3
0
        public void PublishNetworkEvent(INetworkEvent pub)
        {
            if (!_photonView.isMine)
            {
                return;
            }

            _photonView.RPC(RPCDefine.SystemRPC.GetRPCMethod(RPCDefine.SystemRPC.RPCEnum.PublishNetworkEvent), PhotonTargets.All, pub);
        }
コード例 #4
0
ファイル: Networker.cs プロジェクト: beef331/rpg
    private static void DoEvent(NetPacketReader reader)
    {
        NetworkEvents evt = (NetworkEvents)reader.GetByte();

        if (!idToEvent.ContainsKey(evt))
        {
            return;
        }
        INetworkEvent netEvent = (INetworkEvent)Activator.CreateInstance(idToEvent[evt]);

        netEvent.ReadPacket(reader);
        netEvent.Invoke();
    }
コード例 #5
0
ファイル: Actor.cs プロジェクト: hoangvantu/Gem
        public Actor(string name, ContentManager content, Vector2 location, EventManager eventManager, int maxLives)
            : this(name, content, location, maxLives)
        {
            this.livesRemaining = maxLives;
            this.eventManager   = eventManager;
            onLocationChange    = GemClient.Profile("Shooter")
                                  .CreateNetworkEventWithRemoteTime
                                  .AndHandleWith(eventManager, x => new Action <string, float, float, double>(x.SetLocation));

            onShoot = GemClient.Profile("Shooter")
                      .CreateNetworkEventWithRemoteTime
                      .AndHandleWith(eventManager, x => new Action <string, float, float, float, float, double>(x.Shoot));
        }
コード例 #6
0
ファイル: PacketHandler.cs プロジェクト: Erlite/Skaia.NET
 internal void InstantiateNetworkEvent(Type type, byte[] data)
 {
     if (type.IsAssignableFrom(typeof(INetworkEvent)))
     {
         INetworkEvent netEvent = (INetworkEvent)Activator.CreateInstance(type);
         netEvent.Deserialize(data);
         netEvent.HandleEvent();
     }
     else
     {
         // TODO: Log error.
         throw new NotImplementedException("PacketHandler#InstantiateNetworkEvent() when type isn't INetworkEvent.");
     }
 }
コード例 #7
0
ファイル: Networker.cs プロジェクト: beef331/rpg
    private static void SendMessage()
    {
        if (packetsToSend.Count == 0)
        {
            return;
        }
        globalWriter = new NetDataWriter();
        globalWriter.Put(packetsToSend.Count);
        while (packetsToSend.Count > 0)
        {
            INetworkEvent netEvent = packetsToSend.Dequeue();
            netEvent.TryAddPacket(globalWriter);
        }

        if (IsServer)
        {
            server.SendToAll(globalWriter, DeliveryMethod.ReliableOrdered);
        }
        else
        {
            client.SendToAll(globalWriter, DeliveryMethod.ReliableOrdered);
        }
    }
コード例 #8
0
ファイル: Networker.cs プロジェクト: beef331/rpg
 public static void AddPacket(INetworkEvent networkEvent)
 {
     packetsToSend.Enqueue(networkEvent);
 }
コード例 #9
0
 private void RPCPublishNetworkEvent(INetworkEvent pub)
 {
     _messageBroker.Publish(pub);
 }