public void SV_ExecuteClientMessage(ClientNode cl, MsgPacket msg) { msg.Oob = false; int srvID = msg.ReadInt(); cl.messageAcknowledge = msg.ReadInt(); if(cl.messageAcknowledge < 0){ DropClient(cl,"illegible client message"); return; } cl.reliableAcknowledge = msg.ReadInt(); if(cl.reliableAcknowledge < cl.reliableSequence - CConstVar.MAX_RELIABLE_COMMANDS){ DropClient(cl,"illegible client message"); cl.reliableAcknowledge = cl.reliableSequence; return; } if(srvID != serverID ){ // if(serverID >= restartedServerId && srvID < serverID){ // CLog.Info("{0} : ignoring pre map_restart/ outdated client message",cl.name); if(cl.messageAcknowledge > cl.gamestateMessageNum){ SendClientGameState(cl); } return; } // } if(cl.oldServerTime > 0 && srvID == serverID){ CLog.Info("{0} ackownledged gamestate", cl.name); cl.oldServerTime = 0; } int c = 0; do{ c = msg.ReadByte(); if(c == (int)CLC_Cmd.EOF){ break; } if(c != (int)CLC_Cmd.ClientCommand){ break; } if(!ClientCommand(cl, msg)){ return; } if(cl.state == ClientState.ZOMBIE){ return; } }while(true); if(c == (int)CLC_Cmd.MOVE){ UserMove(cl,msg, true); }else if(c == (int)CLC_Cmd.MoveNoDelta){ UserMove(cl,msg,false); }else if(c != (int)CLC_Cmd.EOF){ CLog.Info("bad command type for client!!!!"); } }
private void OnClientStateChanged(object sender, bool connected) { if (listClients.InvokeRequired) { listClients.Invoke((MethodInvoker)(() => { OnClientStateChanged(sender, connected); })); return; } ClientNode node = (ClientNode)sender; if (connected) { ListViewItem client = new ListViewItem(); client.Tag = node; listClients.Items.Add(client); node.Send(new IdentificationPacket()); } else { foreach (ListViewItem item in listClients.Items) { if (item.Tag == node) { listClients.Items.Remove(item); break; } } } }
public void SendProblemGetResponseTest() { var mockcore = new Mock <ClientNodeProcessingModule>(); var mockcreator = new Mock <IMessageArrayCreator>(); var solveRequest = new SolveRequest() { ProblemType = "abc" }; Message[] request = new[] { solveRequest }; mockcreator.Setup(u => u.Create(solveRequest)).Returns(request); mockcore.Setup(u => u.GetRequest()).Returns(solveRequest); var mockclient = new Mock <IClusterClient>(); var shouldReturn = new SolveRequestResponse { Id = 222 }; var responses = new Message[] { new NoOperation(), shouldReturn }; mockclient.Setup(u => u.SendRequests(request)).Returns(responses); var clientNode = new ClientNode(mockclient.Object, mockcore.Object, mockcreator.Object); var ret = clientNode.SendProblem(); Assert.AreEqual(ret, shouldReturn); }
public void SendProblemMultipleResponsesExceptionTest() { var mockcore = new Mock <ClientNodeProcessingModule>(); var mockcreator = new Mock <IMessageArrayCreator>(); var solveRequest = new SolveRequest() { ProblemType = "abc" }; Message[] request = new[] { solveRequest }; mockcreator.Setup(u => u.Create(solveRequest)).Returns(request); mockcore.Setup(u => u.GetRequest()).Returns(solveRequest); var mockclient = new Mock <IClusterClient>(); var shouldReturn = new SolveRequestResponse { Id = 222 }; var duplicated = new SolveRequestResponse { Id = 222 }; var responses = new Message[] { shouldReturn, duplicated }; mockclient.Setup(u => u.SendRequests(request)).Returns(responses); var clientNode = new ClientNode(mockclient.Object, mockcore.Object, mockcreator.Object); var ret = clientNode.SendProblem(); }
public void Open(IPEndPoint[] endpoints, Action <Connection> connectionInitializer = null) { if (endpoints == null || endpoints.Length == 0) { throw new ArgumentNullException("endpoints"); } nodes = new ClientNode[endpoints.Length]; EventHandler clientClosed = ClientClosed; for (int i = 0; i < endpoints.Length; i++) { var node = new ClientNode(this, endpoints[i]); node.Closed += clientClosed; nodes[i] = node; Exception ex = node.TryOpen(connectionInitializer); if (ex != null) { OnConnectFailed(node.EndPoint, ex); Trace.WriteLine(ex.Message); } } UpdateActiveNodeCount(); timer = new Timer(Heartbeat, null, PollFrequency, PollFrequency); }
public override List <Alachisoft.NCache.Common.Monitoring.ClientNode> GetClientList(string cacheId) { List <ClientNode> clients = new List <ClientNode>(); lock (ConnectionManager.ConnectionTable) { IDictionaryEnumerator ide = ConnectionManager.ConnectionTable.GetEnumerator(); while (ide.MoveNext()) { ClientManager clientManager = ide.Value as ClientManager; if (!clientManager.IsDisposed && clientManager.CmdExecuter != null && clientManager.CmdExecuter.ID.ToLower() == cacheId.ToLower()) { ClientNode client = new ClientNode(); IPEndPoint endPoint = clientManager.ClientSocket.RemoteEndPoint as IPEndPoint; client.Address = new Address(endPoint.Address, endPoint.Port); client.ClientID = clientManager.ClientID; if (clientManager.IsDotNetClient) { client.ClientContext = RtContextValue.NCACHE; } else { client.ClientContext = RtContextValue.JVCACHE; } clients.Add(client); } } } return(clients); }
/// <summary> /// /// </summary> /// <param name="clientnode"></param> /// <param name="data"></param> /// <param name="type">(Unreliable,ReliableUnordered,Sequenced,ReliableOrdered,ReliableSequenced),(0,1,2,3,4,5)</param> public static async void RudpSendAsync(this ClientNode clientnode, byte[] data, int type) { if (clientnode.Sender is RUdp rUdp) { await rUdp.RudpSendAsync(data, clientnode.IpEndPoint, type); } }
public void Open(IPEndPoint endpoint, Action <Connection> connectionInitializer = null) { if (endpoint == null) { throw new InvalidOperationException("No EndPoint specified"); } if (node != null) { throw new InvalidOperationException("Already opened"); } var tmp = new ClientNode(this, endpoint); try { Exception ex; if ((ex = tmp.TryOpen(connectionInitializer)) != null) { throw ex; } else if (Interlocked.CompareExchange(ref node, tmp, null) == null) { tmp = null; } } finally { if (tmp != null) { tmp.Close(); } } }
public static void RegisterNode(ClientNode node) { if (!Instance.Nodes.Contains(node)) { Instance.Nodes.Add(node); } }
public UDPInstance(Udp udp, UdpClient udpClient, IPEndPoint ipEndPoint, ClientNode clientNode) : base(clientNode) { _udp = udp; _udpClient = udpClient; IpEndPoint = ipEndPoint; BeginMaintainConnectingAsync(); // 開始進行維持連線之封包發送 }
private bool CreateInstance(TcpClient tcp) { try { IPEndPoint ipEndPoint = tcp.Client.RemoteEndPoint as IPEndPoint; if (ipEndPoint == null) { return(false); } string clientIp = ipEndPoint.ToString(); if (ClientInstance.ContainsKey(clientIp)) { ClientInstance.Remove(clientIp); } // 建立玩家peer實體 ClientNode cNode = _SocketServer.GetPeer(this, ipEndPoint, _SocketServer); //註冊到 mListener 中,讓他的 Receive 功能能被叫 TCPInstance instance = new TCPInstance(this, cNode, tcp); //註冊到 mListener 中,讓他的 Receive 功能能被叫 ClientInstance.Add(clientIp, instance); //成功加入後傳送 Connect 事件給 Client byte[] packet = new byte[] { 1 }; tcp.GetStream().Write(packet, 0, packet.Length); cNode.Initialize(); } catch (Exception e) { Console.WriteLine(e); return(false); } return(true); }
private void SendClientSnapshot(ClientNode client){ byte[] msg_buf = new byte[CConstVar.MAX_MSG_LEN]; //构建snapshot BuildClientSnapshot(client); //机器人有自己的构建方法,不需要发送 if(client.gEntity != null && (client.gEntity.r.svFlags & SVFlags.BOT) != SVFlags.NONE){ return; } //这里要默认开始压缩 MsgPacket msg = new MsgPacket(); msg.Oob = false; msg.AllowOverflow = true; //让客户端知道服务器已经收到的可靠消息。 msg.WriteInt(client.lastClientCommand); //发送任何可靠的服务器指令 UpdateServerCommandsToClient(client, msg); //发送所有的相应的entityState和playerState WriteSnapshotToClient(client, msg); if(msg.Overflowed){ CLog.Info("WARNING: msg overflowed for %s", client.name); msg.Clear(); } SendMessageToClient(msg, client); }
private void OnClientMessageReceived(object sender, IPacket packet) { ClientNode node = (ClientNode)sender; if (packet.GetType() == typeof(IdentificationPacket)) { if (listClients.InvokeRequired) { listClients.Invoke((MethodInvoker)(() => { OnClientMessageReceived(sender, packet); })); return; } IdentificationPacket ident = (IdentificationPacket)packet; foreach (ListViewItem item in listClients.Items) { if (item.Tag == node) { item.Text = ident.Name; item.SubItems.AddRange(new string[] { node.GetClientIdentifier(), ident.MachineName, ident.OperatingSystem, ident.RAM, ident.Version }); break; } } } }
static void Main(string[] args) { MasterNode mn = new MasterNode("Master Node"); ClientNode cn1 = new ClientNode("Client Node 1"); ClientNode cn2 = new ClientNode("Client Node 2"); ClientNode cn3 = new ClientNode("Client Node 3"); mn.SendTransaction(cn1.GetWalletAddress(), 5); mn.SendTransaction(cn2.GetWalletAddress(), 10); mn.SendTransaction(cn3.GetWalletAddress(), 5); mn.StartMining(); cn2.SendTransaction(cn1.GetWalletAddress(), 5); cn3.SendTransaction(mn.GetWalletAddress(), 10); mn.StartMining(); ClientNode cn4 = new ClientNode("Client Node 4"); cn2.SendTransaction(cn4.GetWalletAddress(), 5); cn3.SendTransaction(mn.GetWalletAddress(), 5); mn.StartMining(); Console.WriteLine("The chain is valid: " + mn.IsChainValid()); Console.WriteLine("Masternode has: " + mn.GetWalletBalance(mn.GetWalletAddress()) + " coins"); Console.WriteLine(cn1.Name + " has: " + cn1.GetWalletBalance(cn1.GetWalletAddress()) + " coins"); Console.WriteLine(cn2.Name + " has: " + cn2.GetWalletBalance(cn2.GetWalletAddress()) + " coins"); Console.WriteLine(cn3.Name + " has: " + cn3.GetWalletBalance(cn3.GetWalletAddress()) + " coins"); Console.WriteLine(cn4.Name + " has: " + cn4.GetWalletBalance(cn4.GetWalletAddress()) + " coins"); Console.WriteLine(mn); }
public RUdpInstance(RUdp rUdp, ClientNode clientNode, NetPeer netPeer) : base(clientNode) { _rUdp = rUdp; _netPeer = netPeer; IpEndPoint = _netPeer.EndPoint; BeginMaintainConnectingAsync(); // 開始進行維持連線之封包發送 }
private PlayerState GetClientPlayer(ClientNode node){ int idx = Array.IndexOf(clients, node); if(idx >= 0){ return gameClients[idx]; } return null; }
public override void Init() { instance = this; clients = new ClientNode[CConstVar.MAX_CLIENTS]; for(int i = 0; i < CConstVar.MAX_CLIENTS; i++){ clients[i] = new ClientNode(); } svEntities = new SvEntityState[CConstVar.MAX_GENTITIES]; for(int i = 0; i < CConstVar.MAX_GENTITIES; i++){ svEntities[i] = new SvEntityState(); } // gEntities = new SharedEntity[CConstVar.MAX_GENTITIES]; // for(int i = 0; i < CConstVar.MAX_GENTITIES; i++){ // gEntities[i] = new SharedEntity(); // } worldSectors = new WorldSector[64]; for(int i = 0; i < 64; i++){ worldSectors[i] = new WorldSector(); } configString = new string[CConstVar.MAX_CONFIGSTRINGS]; serverRunning = false; challenges = new SvChallenge[CConstVar.MAX_CHALLENGES]; for(int i = 0; i < CConstVar.MAX_CHALLENGES; i++){ challenges[i] = new SvChallenge(); } numSnapshotEntities = CConstVar.MAX_CLIENTS * CConstVar.PACKET_BACKUP * CConstVar.MAX_SNAPSHOT_ENTITIES; snapshotEntities = new EntityState[numSnapshotEntities]; inited = true; }
public void Dispose() { ClientNode.Clear(); ClientNode = null; Id = ""; ParentId = ""; GC.Collect(); }
private void btnClientDisconnect_Click(object sender, System.EventArgs e) { foreach (ListViewItem item in listClients.SelectedItems) { ClientNode node = (ClientNode)item.Tag; node.Send(new DoShutdownPacket()); } }
public void Initialize(ClientWorld world, ClientStateSettings settings) { _world = world; _network = _world.GetClientNode(); _settings = (SpawnAvatarSettings)settings; _settings.Hide(); _transitionState = ClientStateId.NO_TRANSITION; }
private void UpdateServerCommandsToClient(ClientNode client, MsgPacket msg){ for(int i = client.reliableAcknowledge + 1; i <= client.reliableSequence; i++){ msg.WriteByte((byte)SVCCmd.SERVER_COMMAND); msg.WriteInt(i); msg.WriteString(client.reliableCommands[i&CConstVar.MAX_RELIABLE_COMMANDS]); } client.reliableSent = client.reliableSequence; }
public void SV_ClientThink(ClientNode cl, ref UserCmd cmd){ cmd.CopyTo(cl.lastUserCmd); // CLog.Info("last ucmd time: {0}", cl.lastUserCmd.serverTime); if(cl.state != ClientState.ACTIVE){ return; } CDataModel.GameSimulate.ClientThink(Array.IndexOf(clients, cl)); }
public void CreateNode(double latitude, double longitude) { var node = new ClientNode() { Latitude = latitude, Longitude = longitude }; node = _host.Client.CreateNode(node); }
static void Main(string[] args) { //configure serialization var messageSerializer = new ProtobufMessageSerializer(typeof(Message).Assembly, typeof(JoinRoom).Assembly); var logger = new LoggerConfiguration() .ConfigureMOUSETypesDestructure() .MinimumLevel.Error() .WriteTo.ColoredConsole() .CreateLogger(); var coreEventLogger = new SerilogCoreEvents(logger); //configure network transport provider Action <ISimpleMessageHandlingConfigBuilder> messageHandlingConfigurator = c => c.HandleMessage <RoomEvent>(OnRoomEvent); //Console.WriteLine("Connect to"); Console.WriteLine("Enter how many clients to run simultaneously"); var clientCount = int.Parse(Console.ReadLine()); string roomName = Guid.NewGuid().ToString(); for (int i = 0; i < clientCount; i++) { var transport = new LidgrenNetProvider( new NetPeerConfiguration("Public") { ConnectionTimeout = 30 }, new SerilogLidgrenEvents(logger)); var config = new NetNodeConfig { SendTimeoutSec = 30, ConnectTimeoutSec = 30 }; var node = new ClientNode( //new[] { "127.0.0.1:20001" }, new[] { "rurounisfcluster.westeurope.cloudapp.azure.com:20001" }, transport, coreEventLogger, messageSerializer, messageHandlingConfigurator, config: config); try { node.Start(); node.ExecuteChatUserFlow(roomName).Wait(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } Thread.Sleep(-1); }
public static void GetCurrentChain(ClientNode node) { if (Instance.MasterNodes.Count != 0) { foreach (Block block in Instance.MasterNodes[0].Blocks) { node.AddBlock(block.Clone()); } } }
public ClientWorld(WorldSettings worldSettings, ClientWorldSettings clientWorldSettings) { _worldSettings = worldSettings; _settings = clientWorldSettings; _networkNode = new ClientNode(_worldSettings.commonNodeSettings, _settings.clientNodeSettings); _clientRoom = null; _avatar = null; }
static void Main(string[] args) { ClientNode client = new ClientNode(); string id = client.SpawnNewJob("micmax93", "TestJob", @"F:\workspace\MapReduce.Net\WordCount\bin\Debug\WordCount.WcMapReduce.dll", @"F:\workspace\MapReduce.Net\WordCount\bin\Debug\in\", @"F:\workspace\MapReduce.Net\WordCount\bin\Debug\out.txt"); Console.WriteLine(id); }
//发送下一个fragment和下一个队列中的packet。返回下一个消息可以被发送的毫秒数(基于收到的客户端帧率) //如果没有发送包,就返回-1 private int SVNetChanTransmitNextFragment(ClientNode cl){ if(cl.netChan.unsentFragments){ CNetwork_Server.Instance.NetChanTransmitNextFrame(ref cl.netChan); return RateMsec(cl); }else if(!cl.netChanQueue.IsEmpty){ SVNetChanTransmitNextFragment(cl); return RateMsec(cl); } return -1; }
static void Main(string[] args) { //configure serialization var messageSerializer = new ProtobufMessageSerializer(typeof(Message).Assembly, typeof(JoinRoom).Assembly); var logger = new LoggerConfiguration() .ConfigureMOUSETypesDestructure() .MinimumLevel.Error() .WriteTo.ColoredConsole() .CreateLogger(); var coreEventLogger = new SerilogCoreEvents(logger); //configure network transport provider Action<ISimpleMessageHandlingConfigBuilder> messageHandlingConfigurator = c => c.HandleMessage<RoomEvent>(OnRoomEvent); //Console.WriteLine("Connect to"); Console.WriteLine("Enter how many clients to run simultaneously"); var clientCount = int.Parse(Console.ReadLine()); string roomName = Guid.NewGuid().ToString(); for (int i = 0; i < clientCount; i++) { var transport = new LidgrenNetProvider( new NetPeerConfiguration("Public") { ConnectionTimeout = 30 }, new SerilogLidgrenEvents(logger)); var config = new NetNodeConfig { SendTimeoutSec = 30, ConnectTimeoutSec = 30 }; var node = new ClientNode( //new[] { "127.0.0.1:20001" }, new[] { "rurounisfcluster.westeurope.cloudapp.azure.com:20001" }, transport, coreEventLogger, messageSerializer, messageHandlingConfigurator, config: config); try { node.Start(); node.ExecuteChatUserFlow(roomName).Wait(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } Thread.Sleep(-1); }
private void BotFreeClient(int clientNum){ if(clientNum < 0 || clientNum >= CConstVar.maxClient){ CLog.Error("SV BotFreeClient: bad clientNum: {0}", clientNum); return; } ClientNode cl = clients[clientNum]; cl.state = ClientState.FREE; cl.name = ""; if(cl.gEntity != null){ cl.gEntity.r.svFlags &= ~SVFlags.BOT; } }
public static void HandlePacket(ClientNode client, IPacket packet) { Type packetType = packet.GetType(); if (packetType == typeof(IdentificationPacket)) { CommandHandler.HandleCommand(client, (IdentificationPacket)packet); } else if (packetType == typeof(StringMessagePacket)) { CommandHandler.HandleCommand(client, (StringMessagePacket)packet); } }
public void Open(IPEndPoint[] endpoints, Action<Connection> connectionInitializer = null) { if(endpoints== null || endpoints.Length == 0) throw new ArgumentNullException("endpoints"); nodes = new ClientNode[endpoints.Length]; EventHandler clientClosed = ClientClosed; for(int i = 0 ; i < endpoints.Length ; i++) { var node = new ClientNode(this, endpoints[i]); node.Closed += clientClosed; nodes[i] = node; Exception ex = node.TryOpen(connectionInitializer); if(ex != null) { OnConnectFailed(node.EndPoint, ex); Trace.WriteLine(ex.Message); } } UpdateActiveNodeCount(); timer = new Timer(Heartbeat, null, PollFrequency, PollFrequency); }
public void Open(IPEndPoint endpoint, Action<Connection> connectionInitializer = null) { if (endpoint == null) throw new InvalidOperationException("No EndPoint specified"); if (node != null) throw new InvalidOperationException("Already opened"); var tmp = new ClientNode(this, endpoint); try { Exception ex; if ((ex = tmp.TryOpen(connectionInitializer)) != null) { throw ex; } else if (Interlocked.CompareExchange(ref node, tmp, null) == null) { tmp = null; } } finally { if (tmp != null) tmp.Close(); } }