示例#1
0
 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}");
     }
 }
示例#2
0
        //======================================================================================
        // 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);
        }
示例#3
0
 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);
     }
 }
示例#4
0
        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(); }
        }
示例#5
0
        //======================================================================================
        // 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);
            }
        }
示例#6
0
 //======================================================================================
 // 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);
 }
示例#7
0
 //======================================================================================
 // Purpose: Extendable class for sending a method to call with a protobuf
 // =====================================================================================
 public virtual void route(DataWrapper wrapper, string ID, SocketHandler sh)
 {
 }