public static void routeProtobuf(DataWrapper wrapper, string ID, SocketHandler sh) { if (routes.ContainsKey(wrapper.MsgCase)) { routes[wrapper.MsgCase].route(wrapper, ID, sh); } else { Console.WriteLine($"No route for {wrapper.MsgCase}"); } }
//====================================================================================== // Purpose: Route for datalist protobuf updates UnityDataHolder // ===================================================================================== public override void route(DataWrapper wrapper, string ID, SocketHandler sh) { StringBuilder sb = new StringBuilder(); foreach (var val in wrapper.DataList.Data) { sb.Append(val.Name + ": " + val.Value + "<br>"); } string dataString = sb.ToString(); UnityDataHolder.setString(ID, dataString); }
public override void route(DataWrapper wrapper, string ID, SocketHandler sh) { //====================================================================================== // Purpose: Route for requestCommand protobuf gets command out of CommandBuffer // ===================================================================================== if (CommandBuffer.containsCommand(ID)) { DataWrapper returnWarapper = new DataWrapper(); returnWarapper.ExecuteCommand = new ExecuteCommand(); returnWarapper.ExecuteCommand.Name = CommandBuffer.getFirstCommand(ID); returnWarapper.ExecuteCommand.Args.Add(""); sh.sendToServer(returnWarapper); } }
public UnityConnection() { // register routes for protorouter ProtoRouter.registerRoute(DataWrapper.MsgOneofCase.DataList, new UnityDataRoute()); ProtoRouter.registerRoute(DataWrapper.MsgOneofCase.UnitySettings, new UnityClientListRoute()); ProtoRouter.registerRoute(DataWrapper.MsgOneofCase.CommandChange, new CommandHolderRoute()); ProtoRouter.registerRoute(DataWrapper.MsgOneofCase.GetCommand, new CommandBufferRoute()); TcpListener server = new TcpListener(netConfig.Address, netConfig.Port); try { server.Start(); while (true) { var handler = new SocketHandler(server.AcceptTcpClient()); new Thread(new ThreadStart(handler.HandleConnection)).Start(); } } catch (Exception e) { Console.WriteLine("connect exception " + e, true); } finally { server.Stop(); } }
//====================================================================================== // Purpose: rout for unityInfo protobuf updates UnityClientList // ===================================================================================== public override void route(DataWrapper wrapper, string id, SocketHandler sh) { if (!wrapper.UnitySettings.Name.Equals(id)) { string newID = UnityClientList.registerClient(wrapper.UnitySettings.Name); Console.WriteLine($"UCLR: Name Change {id} to {newID}"); ProtoRouter.clientNameChange(id, newID); UnityClientList.removeClient(id); sh.clientID = newID; id = newID; DataWrapper returnWrapper = new DataWrapper { UnitySettings = new UnitySettings { Name = newID } }; sh.sendToServer(returnWrapper); } if (UnityClientList.clientExists(id)) { Console.WriteLine($"UCLR: client {id} state set to {wrapper.UnitySettings.Public}"); UnityClientList.setClientPublic(id, wrapper.UnitySettings.Public); } }
//====================================================================================== // Purpose: Rout for commandChange protobuf updates CommandHolder // ===================================================================================== public override void route(DataWrapper wrapper, string ID, SocketHandler sh) { CommandHolder.updateCommand(ID, wrapper.CommandChange.Name, wrapper.CommandChange.Value); }
//====================================================================================== // Purpose: Extendable class for sending a method to call with a protobuf // ===================================================================================== public virtual void route(DataWrapper wrapper, string ID, SocketHandler sh) { }