public void sendToAll(LimeMessage message) { foreach (var conn in lidgrenPeer.Connections) { sendTo(conn, message); } }
private void onMessage(LimeMessage msg) { var msgType = msg.GetType(); if (context.config.logMessages) { Global.log.trace($"received message {msgType.Name} from {msg.source}"); } // dynamically resolve the handlers if (handlers.canHandle(msgType)) { var handler = handlers.resolve(msgType); var status = handler.handle(msg); } else { Global.log.err($"no handler found for {msgType.Name}"); } // update last message time var client = context.clients.Single(x => x.uid == msg.source.RemoteUniqueIdentifier); client.lastMessage = stopwatch.ElapsedMilliseconds; }
public void sendTo(NetConnection conn, LimeMessage message) { var packet = lidgrenPeer.CreateMessage(); msgFactory.write(packet, message); lidgrenPeer.SendMessage(packet, conn, message.deliveryMethod); }
public T get <T>() where T : LimeMessage { LimeMessage result = null; if (!messagesByType.TryGetValue(typeof(T), out result)) { throw new ApplicationException("Attempt to get network message of type " + typeof(T) + " failed because that message type hasn't been registered"); } return((T)result); }
public void sendTo(long peerUid, LimeMessage message) { var conn = getConnByUid(peerUid); if (conn == null) { throw new ApplicationException("tried to send message to nonexistent peer"); } sendTo(conn, message); }
protected virtual void onMessage(LimeMessage msg) { var msgType = msg.GetType(); if (msg is GameUpdateMessage gameUpdateMessage) { // preprocess all game updates preprocessGameUpdate(gameUpdateMessage); #if DEBUG if (debug) { Global.log.trace($"received game update {gameUpdateMessage} from {msg.source}"); } #endif } else { // log misc message #if DEBUG if (debug) { Global.log.trace($"received message {msgType.Name} from {msg.source}"); } #endif } if (handlers.canHandle(msgType)) { var handler = handlers.resolve(msgType); var handled = handler.handle(msg); } else { Global.log.err($"no handler found for {msgType.Name}"); } }
public void write(NetOutgoingMessage packet, LimeMessage msg) { packet.Write(msg.id); packet.Write(MsgPackSerializer.SerializeObject(msg)); }
public bool handle(LimeMessage msg) => handle((TMessage)msg);