/// <summary>
        /// This is kind of shitty.  I should just bitshift and copy the lengths, but whatever.  We're not sending
        /// this enough to really care
        /// </summary>
        /// <param name="dataId"></param>
        /// <param name="text"></param>
		public static void SendDataToServer(long dataId, string text)
		{
            /* Let's try something else instead...
			string msgIdString = dataId.ToString();
            string steamIdString = MyAPIGateway.Session.Player.SteamUserId.ToString();

			byte[] data = System.Text.Encoding.ASCII.GetBytes(text);
			byte[] newData = new byte[text.Length + 1 + msgIdString.Length + steamIdString.Length + 1];

            int pos = 0;
			newData[pos] = (byte)msgIdString.Length;
            for (int r = 0; r < msgIdString.Length; r++)
            {
                pos++;
                newData[pos] = (byte)msgIdString[r];
            }
            pos++;

            newData[pos] = (byte)steamIdString.Length;
            for (int r = 0; r < steamIdString.Length; r++ )
            {
                pos++;
                newData[pos] = (byte)steamIdString[r];
            }
            pos++;

            Array.Copy(data, 0, newData, pos, data.Length);*/

            MessageRecieveItem item = new MessageRecieveItem( );
            item.fromID = MyAPIGateway.Session.Player.SteamUserId;
            item.msgID = dataId;
            item.message = text;

            string messageString = MyAPIGateway.Utilities.SerializeToXML<MessageRecieveItem>( item );
            Logging.Instance.WriteLine( messageString );
            /*byte[ ] data = new byte[messageString.Length];

            for ( int r = 0; r < messageString.Length; r++ )
            {
                data[r] = (byte)messageString[r];
            }*/
            byte[ ] data = Encoding.Unicode.GetBytes( messageString );
            MyAPIGateway.Multiplayer.SendMessageToServer(9001, data);
            MyAPIGateway.Multiplayer.SendMessageToServer( 9003, data );
        }
Example #2
0
        public static void SendDataToServer( long dataId, string text )
        {
            var item = new MessageRecieveItem
                       {
                           fromID = MyAPIGateway.Session.Player.SteamUserId,
                           msgID = dataId,
                           message = text
                       };
            //hash a random long with the current time and steamID to make a decent quality guid for each message
            byte[] randLong = new byte[sizeof(long)];
            _random.NextBytes(randLong);
            long uniqueId = 23;
            uniqueId = uniqueId * 37 + BitConverter.ToInt64(randLong, 0);
            uniqueId = uniqueId * 37 + DateTime.Now.GetHashCode();
            uniqueId = uniqueId * 37 + MyAPIGateway.Session.Player.SteamUserId.GetHashCode();

            string messageString = MyAPIGateway.Utilities.SerializeToXML( item );
            byte[] messageBytes = Encoding.UTF8.GetBytes( messageString );
            byte[] data = new byte[messageBytes.Length + sizeof(long)];
            BitConverter.GetBytes( uniqueId ).CopyTo( data, 0 );
            messageBytes.CopyTo( data, sizeof(long) );

            MyAPIGateway.Multiplayer.SendMessageToServer( 9001, data );
            //MyAPIGateway.Multiplayer.SendMessageToServer( 9003, data );
        }