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); }
internal static void RegisterEvent(INetworkEvent ev) { if (events == null) { events = new Dictionary <byte, INetworkEvent>(); } events.Add(ev.Code, ev); }
public void PublishNetworkEvent(INetworkEvent pub) { if (!_photonView.isMine) { return; } _photonView.RPC(RPCDefine.SystemRPC.GetRPCMethod(RPCDefine.SystemRPC.RPCEnum.PublishNetworkEvent), PhotonTargets.All, pub); }
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(); }
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)); }
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."); } }
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); } }
public static void AddPacket(INetworkEvent networkEvent) { packetsToSend.Enqueue(networkEvent); }
private void RPCPublishNetworkEvent(INetworkEvent pub) { _messageBroker.Publish(pub); }