本文整理汇总了C#中NetMessageType类的典型用法代码示例。如果您正苦于以下问题:C# NetMessageType类的具体用法?C# NetMessageType怎么用?C# NetMessageType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetMessageType类属于命名空间,在下文中一共展示了NetMessageType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.DebugMessage:
Console.WriteLine(buffer.ReadString());
break;
case NetMessageType.StatusChanged:
NetConnectionStatus status = source.Status;
if (status == NetConnectionStatus.Connected)
{
source.Tag = ImageClientStatus.JustConnected;
s_nextPixelToSend[source] = 0;
}
else if (status == NetConnectionStatus.Disconnected)
{
if (s_nextPixelToSend.ContainsKey(source))
s_nextPixelToSend.Remove(source);
}
break;
case NetMessageType.Receipt:
source.Tag = ImageClientStatus.Running;
break;
default:
// unhandled
break;
}
}
示例2: HandleMessage
private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.StatusChanged:
if (source.LocalHailData == null)
source.LocalHailData = Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode());
if (source.RemoteHailData != null)
WriteToConsole("New status: " + source.Status + " - remote hail is: " + Encoding.ASCII.GetString(source.RemoteHailData));
else
WriteToConsole("New status: " + source.Status + " - remote hail is null");
break;
case NetMessageType.DebugMessage:
case NetMessageType.VerboseDebugMessage:
case NetMessageType.BadMessageReceived:
case NetMessageType.ConnectionRejected:
WriteToConsole(buffer.ReadString());
break;
case NetMessageType.Data:
WriteToConsole(source.RemoteEndpoint + " writes: " + buffer.ReadString());
break;
case NetMessageType.ServerDiscovered:
// discovered another peer!
s_peer.Connect(buffer.ReadIPEndPoint(), Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode()));
break;
default:
// unhandled
break;
}
}
示例3: ReadMessage
public bool ReadMessage(NetBuffer intoBuffer, out NetMessageType type, out INetConnection sender)
{
NetConnection senderInternal;
bool messageExists = _netServer.ReadMessage(intoBuffer, out type, out senderInternal);
sender = new NetConnectionWrapper(senderInternal);
return messageExists;
}
示例4: Reset
internal void Reset()
{
m_messageType = NetMessageType.LibraryError;
m_bitLength = 0;
m_isSent = false;
NetException.Assert(m_recyclingCount == 0);
m_fragmentGroup = 0;
}
示例5: Reset
internal void Reset()
{
m_messageType = NetMessageType.LibraryError;
m_bitLength = 0;
m_isSent = false;
m_recyclingCount = 0;
m_fragmentGroup = 0;
}
示例6: NetMessage
//private Byte[] recBuffer;
public NetMessage()
{
type = NetMessageType.NONE;
m_terminalID = "";
clientID = -1;
//bytes = 0;
msg = String.Empty;
//recBuffer = new Byte[256];
}
示例7: Reset
internal void Reset()
{
m_incomingMessageType = NetIncomingMessageType.Error;
m_readPosition = 0;
m_receivedMessageType = NetMessageType.LibraryError;
m_senderConnection = null;
m_bitLength = 0;
m_isFragment = false;
}
示例8: AddMessageHandler
public void AddMessageHandler(NetMessageType messageType , Action<NetMessageType, NetIncomingMessage> handler)
{
if(!messagehandler.ContainsKey(messageType))
{
messagehandler[messageType] = new List<Action<NetMessageType,NetIncomingMessage>>();
messagehandler[messageType].Add(handler);
}
else
{
messagehandler[messageType].Add(handler);
}
}
示例9: ReceivedSequencedMessage
// returns true if message should be rejected
internal bool ReceivedSequencedMessage(NetMessageType mtp, ushort seqNr)
{
int slot = (int)mtp - (int)NetMessageType.UserSequenced;
int diff = Relate(seqNr, m_lastReceivedSequenced[slot]);
if (diff == 0)
return true; // reject; already received
if (diff > (ushort.MaxValue / 2))
return true; // reject; out of window
m_lastReceivedSequenced[slot] = seqNr;
return false;
}
示例10: GetSendSequenceNumber
internal ushort GetSendSequenceNumber(NetMessageType mtp)
{
if (mtp < NetMessageType.UserSequenced)
return 0;
int slot = (int)mtp - (int)NetMessageType.UserSequenced;
int retval;
lock (m_nextSendSequenceNumber)
{
retval = m_nextSendSequenceNumber[slot];
if (retval == ushort.MaxValue)
retval = -1;
m_nextSendSequenceNumber[slot] = retval + 1;
}
return (ushort)retval;
}
示例11: RecieveCreateNetworkObjectOnServer
void RecieveCreateNetworkObjectOnServer(NetMessageType NetMessageType, NetIncomingMessage NetIncomingMessage)
{
String ident = NetIncomingMessage.ReadString();
if (NetWorkObjects.ContainsKey(ident))
{
ServerIObject obj = NetWorkObjects[ident].CreateLoadObjectOrder(NetIncomingMessage);
world.AddObject(obj);
//skip the message type
NetIncomingMessage.Position = sizeof(short) * 8;
NetOutgoingMessage o = CreateMessage(NetWorking.NetMessageType.CreateNetworkObjectOnClient);
o.Write(obj.GetId());
NetOutgoingMessage mes = NetWorkObjects[ident].CreateRedistributeOrder(obj, NetIncomingMessage, o);
this.SendMessageToAllClients(mes,NetDeliveryMethod.ReliableOrdered);
}
}
示例12: HandleEchoMessage
void HandleEchoMessage(NetMessageType NetMessageType, NetIncomingMessage NetIncomingMessage)
{
String ident = NetIncomingMessage.ReadString();
long unique = NetIncomingMessage.ReadInt64();
if(NetWorkEcho.ContainsKey(ident))
{
NetOutgoingMessage o = CreateMessage(NetWorking.NetMessageType.Echo);
o.Write(ident);
o.Write(unique);
SendMessageToAllClients(NetWorkEcho[ident].AnswerMessage(NetIncomingMessage,o),NetDeliveryMethod.ReliableOrdered);
}
}
示例13: CreateMessage
public NetOutgoingMessage CreateMessage(NetMessageType messageType)
{
NetOutgoingMessage mes = server.CreateMessage();
mes.Write((short)messageType);
return mes;
}
示例14: ReceivedUnconnectedLibraryMessage
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
{
NetConnection shake;
if (m_handshakes.TryGetValue(senderEndpoint, out shake))
{
shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
//
// Library message from a completely unknown sender; lets just accept Connect
//
switch (tp)
{
case NetMessageType.Discovery:
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
{
NetIncomingMessage dm = CreateIncomingMessage(NetIncomingMessageType.DiscoveryRequest, payloadByteLength);
if (payloadByteLength > 0)
Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength);
dm.m_receiveTime = now;
dm.m_bitLength = payloadByteLength * 8;
dm.m_senderEndpoint = senderEndpoint;
ReleaseMessage(dm);
}
return;
case NetMessageType.DiscoveryResponse:
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse))
{
NetIncomingMessage dr = CreateIncomingMessage(NetIncomingMessageType.DiscoveryResponse, payloadByteLength);
if (payloadByteLength > 0)
Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength);
dr.m_receiveTime = now;
dr.m_bitLength = payloadByteLength * 8;
dr.m_senderEndpoint = senderEndpoint;
ReleaseMessage(dr);
}
return;
case NetMessageType.NatIntroduction:
HandleNatIntroduction(ptr);
return;
case NetMessageType.NatPunchMessage:
HandleNatPunch(ptr, senderEndpoint);
return;
case NetMessageType.Connect:
// proceed
break;
case NetMessageType.Disconnect:
// this is probably ok
LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint);
return;
default:
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
return;
}
// It's someone wanting to shake hands with us!
int reservedSlots = m_handshakes.Count + m_connections.Count;
if (reservedSlots >= m_configuration.m_maximumConnections)
{
// server full
NetOutgoingMessage full = CreateMessage("Server full");
full.m_messageType = NetMessageType.Disconnect;
SendLibrary(full, senderEndpoint);
return;
}
// Ok, start handshake!
NetConnection conn = new NetConnection(this, senderEndpoint);
m_handshakes.Add(senderEndpoint, conn);
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
示例15: ReceivedUnconnectedLibraryMessage
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
{
NetConnection shake;
if (m_handshakes.TryGetValue(senderEndpoint, out shake))
{
shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
//
// Library message from a completely unknown sender; lets just accept Connect
//
switch (tp)
{
case NetMessageType.Discovery:
HandleIncomingDiscoveryRequest(now, senderEndpoint, ptr, payloadByteLength);
return;
case NetMessageType.DiscoveryResponse:
HandleIncomingDiscoveryResponse(now, senderEndpoint, ptr, payloadByteLength);
return;
case NetMessageType.NatIntroduction:
HandleNatIntroduction(ptr);
return;
case NetMessageType.NatPunchMessage:
HandleNatPunch(ptr, senderEndpoint);
return;
case NetMessageType.ConnectResponse:
lock (m_handshakes)
{
foreach (var hs in m_handshakes)
{
if (hs.Key.Address.Equals(senderEndpoint.Address))
{
if (hs.Value.m_connectionInitiator)
{
//
// We are currently trying to connection to XX.XX.XX.XX:Y
// ... but we just received a ConnectResponse from XX.XX.XX.XX:Z
// Lets just assume the router decided to use this port instead
//
var hsconn = hs.Value;
m_connectionLookup.Remove(hs.Key);
m_handshakes.Remove(hs.Key);
LogDebug("Detected host port change; rerouting connection to " + senderEndpoint);
hsconn.MutateEndpoint(senderEndpoint);
m_connectionLookup.Add(senderEndpoint, hsconn);
m_handshakes.Add(senderEndpoint, hsconn);
hsconn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
}
}
}
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
return;
case NetMessageType.Connect:
// proceed
break;
case NetMessageType.Disconnect:
// this is probably ok
LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint);
return;
default:
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
return;
}
// It's someone wanting to shake hands with us!
int reservedSlots = m_handshakes.Count + m_connections.Count;
if (reservedSlots >= m_configuration.m_maximumConnections)
{
// server full
NetOutgoingMessage full = CreateMessage("Server full");
full.m_messageType = NetMessageType.Disconnect;
SendLibrary(full, senderEndpoint);
return;
}
// Ok, start handshake!
NetConnection conn = new NetConnection(this, senderEndpoint);
m_handshakes.Add(senderEndpoint, conn);
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}