(WIP) Lottery Statistics

Discussion in 'General Discussion' started by xerxesbeat, Aug 26, 2014.

?

How bad do you want it

  1. /ignore

    6.3%
  2. meh, it would be kinda neat

    28.1%
  3. definitely important to my enjoyment of the ECC lotto

    28.1%
  4. DO IT OR I WILL HUNT YOU DOWN AND MURDER YOUR BABIES

    37.5%
  1. xerxesbeat

    xerxesbeat Builder
    Builder ⛰️ Ex-Mayor ⚒️⚒️

    Joined:
    Mar 28, 2012
    Messages:
    32
    Trophy Points:
    25,235
    Ratings:
    +7
    Edit: I will probably not return to this as a project, so here is the code if you want to collect stats yourself

    Stats are in the format "<unix time (ms)>,<winner username>,<amount won>,<winner's tickets>,<total players>,<total tickets>\n"

    Uses MCProtocolLib
    Code:
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Calendar;
    import java.util.LinkedList;
    
    import org.spacehq.mc.auth.exception.AuthenticationException;
    import org.spacehq.mc.protocol.MinecraftProtocol;
    import org.spacehq.mc.protocol.data.message.Message;
    import org.spacehq.mc.protocol.packet.ingame.client.ClientChatPacket;
    import org.spacehq.packetlib.Client;
    import org.spacehq.packetlib.Session;
    import org.spacehq.packetlib.event.session.ConnectedEvent;
    import org.spacehq.packetlib.event.session.DisconnectedEvent;
    import org.spacehq.packetlib.event.session.DisconnectingEvent;
    import org.spacehq.packetlib.event.session.PacketReceivedEvent;
    import org.spacehq.packetlib.event.session.PacketSentEvent;
    import org.spacehq.packetlib.event.session.SessionListener;
    import org.spacehq.packetlib.packet.Packet;
    import org.spacehq.packetlib.tcp.TcpSessionFactory;
    
    public class LottoBot implements SessionListener
    {
        private static final String user = "<username>", pass = "<password>";
        private static boolean check = true;
        static LottoBot bot = null;
    
        public static void main ( String [] args )
        {
            bot = new LottoBot ( user );
            try
            {
                bot.login( pass );
            }
            catch ( Exception e )
            {
                e.printStackTrace();
            }
        }
    
        private static final String RX_USER = "(\\*\\*)?[a-zA-Z0-9_]+";
        public static void parseChat ( String message )
        { // TODO parse /rn
            if ( message.startsWith( "[LOTTERY] " ) )
            {
                System.out.println( message );
                message = message.substring( 10 );
                /*if ( message.matches( RX_USER + " just bought [0-9]+ ticket(s)?!( Draw in " + RX_DURATION + ")?" ) )
                {
                    String name = message.substring( 0, message.indexOf( " " ) );
                    String qty = message.substring( message.indexOf( " bought " ) + 8, message.indexOf( " ticket" ) );
                }
                else*/
                if ( message.matches( "Congratulations go to " + RX_USER + " for winning \\$[0-9\\.]+ with [0-9]+ ticket(s)?[!\\.]?" ) )
                {
                    endTime = Calendar.getInstance().getTimeInMillis();
                    winPlayer = message.substring( message.indexOf( "to " ) + 3, message.indexOf( " for w" ) );
                    winAmount = message.substring( message.indexOf( "g $" ) + 3, message.indexOf( " with " ) );
                    winTickets = message.substring( message.indexOf( " with " ) + 6, message.indexOf( " ticket" ) );
                    //System.err.println( "\"" + name + "\" won $" + amt + " with " + qty + " ticket(s)" );
                }
                else if ( message.matches( "There was a total of [0-9]+ player(s)? buying [0-9]+ ticket(s)?" ) )
                {
                    totalPlayers = message.substring( message.indexOf( " of " ) + 4, message.indexOf( " player" ) );
                    totalTickets = message.substring( message.indexOf( " buying " ) + 8, message.indexOf( " ticket" ) );
                    //System.err.println( "Lottery ended with " + players + " player(s) buying " + qty + " ticket(s)" );
                    save();
                }
            }
        }
    
        private static long endTime;
        private static String winPlayer, winAmount, winTickets, totalPlayers, totalTickets;
        private static void save ()
        {
            if ( endTime != 0 && winPlayer != null && winAmount != null
                && winTickets != null && totalPlayers != null && totalTickets != null )
            {
                try
                {
                    FileOutputStream out = new FileOutputStream ( "lotto.log", true );
                    out.write( ( endTime + "," + winPlayer + "," + winAmount + "," + winTickets + "," + totalPlayers + "," + totalTickets + "\n" ).getBytes() );
                    out.close();
                }
                catch ( IOException e )
                {
                    e.printStackTrace();
                }
            }
            endTime = 0;
            winPlayer = winAmount = winTickets = totalPlayers = totalTickets = null;
        }
    
        private String serverAddress = "mc.ecocitycraft.com";
        private int serverPort = 25565;
        private String username;
    
        private Client client;
    
        public LottoBot ( String username )
        {
            this.username = username;
        }
    
        public void login ( String password ) throws AuthenticationException
        {
            MinecraftProtocol protocol = new MinecraftProtocol ( username, password, false );
            client = new Client ( serverAddress, serverPort, protocol, new TcpSessionFactory () );
            Session session = client.getSession();
            session.addListener( this );
            session.connect();
        }
    
        public void chat ( String message )
        {
            client.getSession().send( new ClientChatPacket ( message ) );
        }
    
        public void packetReceived ( PacketReceivedEvent event )
        {
            Packet pkt = event.getPacket();
            if ( pkt == null )
                return;
            if ( pkt instanceof org.spacehq.mc.protocol.packet.ingame.server.ServerChatPacket )
            {
                LottoBot.parseChat( ( (org.spacehq.mc.protocol.packet.ingame.server.ServerChatPacket) pkt ).getMessage().getFullText() );
            }
        }
    
        public void packetSent ( PacketSentEvent event ) {}
        public void connected ( ConnectedEvent event ) {}
        public void disconnecting ( DisconnectingEvent event ) {}
        public void disconnected ( DisconnectedEvent event ) {}
    
    }
    
     
    #1 xerxesbeat, Aug 26, 2014
    Last edited: Aug 28, 2014
  2. donkey5k

    donkey5k •| The Legendary Donkey |•
    Builder ⛰️ Ex-EcoLeader ⚜️⚜️⚜️ Premium Upgrade

    Joined:
    May 14, 2013
    Messages:
    1,584
    Trophy Points:
    48,510
    Gender:
    Male
    Ratings:
    +492
    The Link Isn't Working..

    And I'm interested! I'd love to see this!
     
    #2 donkey5k, Aug 26, 2014
    Last edited: Aug 26, 2014
  3. xerxesbeat

    xerxesbeat Builder
    Builder ⛰️ Ex-Mayor ⚒️⚒️

    Joined:
    Mar 28, 2012
    Messages:
    32
    Trophy Points:
    25,235
    Ratings:
    +7
  4. Dccciz

    Dccciz Nicememer55
    Builder ⛰️ Ex-Tycoon ⚜️⚜️⚜️ Premium Upgrade

    Joined:
    Mar 8, 2013
    Messages:
    2,830
    Trophy Points:
    50,090
    EcoDollars:
    $0
    Ratings:
    +2,061
    I have a very very small amount of knowledge in html/css. I don't think it will be of much help.

    @JamieSinn
     
    #4 Dccciz, Aug 26, 2014
    Last edited: Aug 26, 2014
  5. thehockeykids2

    thehockeykids2 Builder
    Builder ⛰️ Ex-President ⚒️⚒️

    Joined:
    Apr 10, 2012
    Messages:
    2,648
    Trophy Points:
    49,590
    Gender:
    Male
    Ratings:
    +1,581
    I know a fair bit of html, I may be of help, it all depends on how "professional" you want it to be :p
     
    #5 thehockeykids2, Aug 26, 2014
    Last edited: Aug 27, 2014
  6. donkey5k

    donkey5k •| The Legendary Donkey |•
    Builder ⛰️ Ex-EcoLeader ⚜️⚜️⚜️ Premium Upgrade

    Joined:
    May 14, 2013
    Messages:
    1,584
    Trophy Points:
    48,510
    Gender:
    Male
    Ratings:
    +492
    The old one was formatted fairly well and my suggestion for this one is create a profile for each user to keep track of instead just a bunch of people all together.
     
  7. xerxesbeat

    xerxesbeat Builder
    Builder ⛰️ Ex-Mayor ⚒️⚒️

    Joined:
    Mar 28, 2012
    Messages:
    32
    Trophy Points:
    25,235
    Ratings:
    +7
    I don't need it to be particularly professional, just reasonable looking enough to make it comfortable to the eyes
    As for the user profile thing, I don't want to have to have people register, but I was trying to think of ways you could enter your username and verify with the bot ingame so you didn't need a password. choosing to stay logged in if desired
     
  8. thehockeykids2

    thehockeykids2 Builder
    Builder ⛰️ Ex-President ⚒️⚒️

    Joined:
    Apr 10, 2012
    Messages:
    2,648
    Trophy Points:
    49,590
    Gender:
    Male
    Ratings:
    +1,581
    I'm pretty sure I could do that. Contact me on skype for easier communication. "marc17thehockeykids2"
     
  9. Mochocrap

    Mochocrap Lannister
    EcoLegend ⛰️⛰️⛰️⛰️ Ex-EcoLeader ⚜️⚜️⚜️ Prestige ⭐ II ⭐ Premium Upgrade

    Joined:
    Jul 20, 2013
    Messages:
    1,304
    Trophy Points:
    70,160
    Gender:
    Male
    Ratings:
    +778
    This isn't necessary HTML as it is java code people.. The first four lines destinguish specifically java, so HTML and CSS won't get you far really at all.... I took classes on HTML (easiest coding ever) last year as well as CSS, I created an amateur Gta website for the final project:p and this year I'm taking ap computer science, aka java atm and what I want to major in college. To be completely honest I thought that something like this would be extremely difficult to understand and play with, but I already see similar formatting and common terms in the code as I see in my class. And it's only been about 3 weeks xD this final project will be to construct a game in like 3 days, but seeing this code linked in the description makes me smile:)
    CSS was first developed in 1997, as a way for Web developers to define the look and feel of their Web pages. It was intended to allow developers to separate content from design so that HTML could perform more of the function that it was originally based on - the markup of content, without worry about the design and layout.
    Hypertext Markup Language, a standardized system for tagging text files to achieve font, color, graphic, and hyperlink effects on World Wide Web pages.
     
    #9 Mochocrap, Sep 5, 2014
    Last edited: Sep 5, 2014