ItsMods

Full Version: Steamreader/writer problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi again Smile
As you can see i want to be able to save points using !shop, now i rent my servers so it can't be to C: drive etc, i have access to ftp and www.

iv'e even tried to use this in C: drive to to see if it gives any errors in log etc but it doesn't, and yet doesn't seem to work at all, The current destination seems irrelevant to what i put in , whether it's C:\\mw3\\shop or what ever. Odd thing when i initially put the code in i did get a error message in log saying it couldn't find xuid 12234456 etc, but then the point wasn't working. Rock kindly help me in placing the code without c# errors but still doesn't work.

Help is appreciated.


PHP Code:
public override void OnPlayerConnect(ServerClient Client)
        {
            try
            {
                
StreamReader reader = new StreamReader(@"shop" Client.XUID ".txt");
                
ServerPrint("StatswillbeWritten2");
               
                
string read reader.ReadLine();
                
string read2 read;

                
string[] readArray read2.Split('=');
                
Points[Client.XUID] = int.Parse(readArray[1]);
            }

            catch { } 

PHP Code:
public override int OnPlayerDamaged(ServerClient AttackerServerClient Victimstring Weaponint Damage)
        {
            if (
Damage >= Victim.Other.Health && Attacker.Team != Victim.Team && Victim.XUID != Attacker.XUID)
            {
                try
                {
                    
Points[Attacker.XUID] = (((int)Points[Attacker.XUID]) + 120);
                    
StreamWriter writer = new StreamWriter(@"shop" Attacker.XUID ".txt");
                   
                  
                    
int points = (int)Points[Attacker.XUID];

                    
writer.WriteLine(Attacker.XUID "=" points.ToString());
                    
writer.Dispose();
                    
writer.Close();
                }
                catch { } 
Replace all try... catch blocks with this:

Code:
try
{
    // blah blah.
}
catch(Exception ex)
{
    ServerPrint(ex.ToString());
}

See what comes up in the console.
Thanks @master131

Here is the log error
System.IO.FileNotFoundException: Could not find file 'G:\mw3server\mw3\shop01100001045752e1.txt'.

File name: 'G:\mw3server\mw3\shop01100001045752e1.txt'

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)

at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)

at System.IO.StreamReader..ctor(String path)

at mw3zombie.mw3shop.OnPlayerConnect(ServerClient Client)
(02-23-2013, 14:01)hillbilly Wrote: [ -> ]Thanks @master131

Here is the log error
System.IO.FileNotFoundException: Could not find file 'G:\mw3server\mw3\shop01100001045752e1.txt'.

File name: 'G:\mw3server\mw3\shop01100001045752e1.txt'

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)

at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)

at System.IO.StreamReader..ctor(String path)

at mw3zombie.mw3shop.OnPlayerConnect(ServerClient Client)

(@"shop\\" + Client.XUID + ".txt");
(@"shop\\" + Attacker.XUID + ".txt");

You already tried to kill someone and look if it created the file?
It wont create the txt file but even if i create it i still get this error

System.NullReferenceException: Object reference not set to an instance of an object.

at mw3zombie.mw3shop.OnPlayerConnect(ServerClient Client)
(02-23-2013, 14:27)hillbilly Wrote: [ -> ]It wont create the txt file but even if i create it i still get this error

System.NullReferenceException: Object reference not set to an instance of an object.

at mw3zombie.mw3shop.OnPlayerConnect(ServerClient Client)

file name should be your xuid and the text inside should be yourxuid=points

I'm using the same code and everything is working fine for me.
i did create the txt file with my xuid as it's name but i still get the error above, main point is that it wont even create the txt file to start with.

If i create the file, put in the points manually then on connect it load ok no errors, and loads the points, maybe to do with permission on creating the file and writing to it, ??
anyone?
Why not use the static File methods? I never bothered StreamReader and Writer
tis ok for what ever reason it started to work.