Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SERVER
- */
- //This method is running on FixedUpdate
- //FixedUpdate is set to 60 Ticks, so we have a 60 Tickrate
- internal void Listen()
- {
- if (!m_host.IsSet) return;
- if (m_host.Service(0, out UDPEvent evnt))
- {
- switch (evnt.Type)
- {
- case UDPEventType.Connect:
- //Add the Event Peer as a new Connection
- AddConnection(evnt.Peer);
- break;
- case UDPEventType.Disconnect:
- //Tell everyone, that Player XY is disconnected
- ResponseClientDisconnected(RemoveConnection(evnt.Peer.GetRemoteAddress()));
- break;
- case UDPEventType.Receive:
- //Process incoming Packets and forwared it to other Players
- ProcessPackets(evnt.Packet, GetClient(evnt.Peer.GetRemoteAddress()));
- evnt.Packet.Dispose();
- break;
- }
- }
- }
- /* CLIENT */
- internal void Connect(string _ip, ushort _port)
- {
- if (isConnected)
- return;
- UDPAddress address = new UDPAddress();
- address.SetHost(_ip);
- address.Port = _port;
- m_peer = new UDPPeer();
- m_peer = m_host.Connect(address, m_config.channelLimit, 0);
- if (m_host.Service(5000, out UDPEvent evnt))
- {
- if (evnt.Type == UDPEventType.Connect)
- {
- //Create a new Connection with the Event Peer
- m_connection = new Connection(evnt.Peer);
- //Send a Message to Server, requesting Client ID
- RequestClientIDEvent RPIDEvent = new RequestClientIDEvent();
- RPIDEvent.version = m_version;
- RPIDEvent.name = playerName;
- m_connection.SendEventCS(RPIDEvent);
- }
- }
- else
- {
- SkyLog.Error("Can't connect");
- m_peer.Reset();
- }
- }
- //This method is running on FixedUpdate
- //FixedUpdate is set to 60 Ticks, so we have a 60 Tickrate
- internal void Listen()
- {
- if (!m_host.IsSet) return;
- if (m_host.Service(0, out UDPEvent evnt))
- {
- if (evnt.Type == UDPEventType.Receive)
- {
- //Process Packets
- ProcessPackets(evnt.Packet);
- evnt.Packet.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement