예제 #1
0
        private void MessageReceived(TimestampedBytes data)
        {
            // The plugin did send us a Message, how nice :)
            // It will be raw data and needs to be decoded by the type (first byte)
            // Using the acPlugins4net library we can directly receive a PluginMessage
            var msg = AcMessageParser.Parse(data);

            AwesomeViewerStolenFromTheInternet.Log(msg);

            // if there is a Request, we'll have to send the corresponding answer.
            if (msg.Type == ACSProtocol.MessageType.ACSP_GET_CAR_INFO)
            {
                var request  = msg as RequestCarInfo;
                var response = CarInfoConfiguration.GetMessage(request.CarId);
                UDPServer.TrySend(response.ToBinary());
            }

            /*
             * // Currently we only have two very simple messages, so we're do it here:
             * try
             * {
             *  using (var br = new BinaryReader(new MemoryStream(data)))
             * {
             *  var msgType = (ACSProtocol.MessageType)br.ReadByte();
             *  switch (msgType)
             *  {
             *      case ACSProtocol.MessageType.ACSP_GET_CAR_INFO:
             *          {
             *              // The plugin asks for the car_info of car_id X
             *              var requested_car_id = br.ReadByte();
             *
             *              // Then it expects a single answer
             *              var carInfoMsg = new MsgCarInfo() { CarId = requested_car_id, CarModel = "bmw_e300", CarSkin = "anthrazit", DriverName = "Minolin", DriverTeam = "Team", DriverGuid = "2468274569", IsConnected = true };
             *              UDPServer.TrySend(carInfoMsg);
             *          }
             *          break;
             *      case ACSProtocol.MessageType.ACSP_REALTIMEPOS_INTERVAL:
             *          {
             *          }
             *          break;
             *      default:
             *          throw new Exception("Unknown/unexpected incoming message type '" + msgType + "'");
             *  }
             * }
             *  }
             * catch(Exception ex)
             * {
             *  System.Windows.MessageBox.Show(ex.Message);
             * }*/
        }
예제 #2
0
        public void SendMessage(PluginMessage msg)
        {
            var success = UDPServer.TrySend(msg.ToBinary());

            AwesomeViewerStolenFromTheInternet.Log(msg);
        }