private void RemoveClient(Remote r) { r.ReceiveCount = 100; Connection.Block(r); if (r.Data == null) { return; } _Clients.Remove((ClientInfo)r.Data); ConnectionSelectForm.Log("[D] Client " + _Clients.Count); }
public void OnPacket(Remote r) { var type = (PacketType)Parent.Connection.Buffer.ReadByte(); switch (type) { case PacketType.NewConnection: //TODO return; case PacketType.ClientReady: ConnectionSelectForm.Log("Ready " + r.ToString()); _Ready[RemoteIndex(r)] = true; CheckReady(); return; case PacketType.ClientStatus: //ignore return; case PacketType.ClientInputData: // Parent.Connection.Buffer.ReadBytes(_ByteBuffer); Parent._InputHandler.ReceiveNetworkData(RemoteIndex(r), _ByteBuffer); return; default: break; } }
public void OnPacket(Remote r) { var type = (PacketType)_Parent.Connection.Buffer.ReadByte(); switch (type) { case PacketType.None: //empty packet r.ReceiveCount -= 1; _Parent.Connection.Buffer.Write(PacketType.None); _Parent.Connection.Send(r); return; case PacketType.NewConnection: if (r.ReceiveCount == 1) { ClientInfo ci = new ClientInfo(); ci.Remote = r; r.Data = ci; _Parent._Clients.Add(ci); //just reply SendStatus(r); ConnectionSelectForm.Log("New client " + r.ToString()); ConnectionSelectForm.Log("[A] Client " + _Parent._Clients.Count); return; } break; case PacketType.ClientStatus: if (r.ReceiveCount != 1) { //TODO check if active client //we don't need any information, just reply SendStatus(r); ConnectionSelectForm.Log("Client status " + r.ToString()); return; } break; default: break; } ConnectionSelectForm.Log("Error"); _Parent.RemoveClient(r); }
private void SendStatus(Remote r) { _Parent.Connection.Buffer.Write(PacketType.ServerStatus); _Parent.Connection.Send(r); }
public bool Receive(out Remote r) { var rr = Receive(); r = rr; return rr != null; }
private int RemoteIndex(Remote r) { return ((ClientInfo)r.Data).PlayerIndex; }
public void Block(Remote r) { var k = GetKey(ref r.Address); _BlockRemote.Add(k); _RemoteList.Remove(k); }
private Remote FindRemote(ref WinSock.sockaddr_in addr) { var val = GetKey(ref addr); if (_BlockRemote.Contains(val)) { return null; } Remote ret; if (_RemoteList.TryGetValue(val, out ret)) { ret.LastReceived = _Clock.ElapsedMilliseconds; return ret; } ret = new Remote(ref addr, _Clock.ElapsedMilliseconds); _RemoteList.Add(val, ret); return ret; }
public bool UpdateRemoteList(Remote r, long receiveTimeout, long activeTimeout) { // return true; long removeSend = _Clock.ElapsedMilliseconds - receiveTimeout; long activeTime = _Clock.ElapsedMilliseconds - activeTimeout; _ToRemove.Clear(); if (r.LastReceived < r.LastSend && r.LastSend < removeSend || r.LastSend < activeTime && r.LastReceived < activeTime) { _RemoteList.Remove(GetKey(ref r.Address)); return false; } return true; }
public void Unblock(Remote r) { var k = GetKey(ref r.Address); _BlockRemote.Remove(k); }
public void Send(Remote r) { if (WinSock.sendto(_Socket, Buffer.Pointer, Buffer.Length, 0, ref r.Address, WinSock.sockaddr_in.Size) < 0) { throw new NetworkException(Marshal.GetLastWin32Error()); } }