Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- (c)2009 xprog.ch technologies. All rights reserved.
- Created by Nicolas Hafner(Root)
- boolean name(String a){
- try{
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- */
- import java.io.*;
- import java.util.*;
- import java.util.zip.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.sql.*;
- import org.apache.commons.net.ftp.*;
- public class Voc extends JFrame{
- //window constants
- static int h = 600;static int w = 400;
- static int dh = 400;static int dw = 400;
- static int ih = 100;static int iw = 400;
- static int eh = 600;static int ew = 500;
- //pw's and greeting variables
- int stage = 0; //stages: 0-program start 1-questioning 2-result 3-stats 4-read file 5-debug 6-sql read 7-sql write 8-voc write 9-sql get 10-admin mode active 11-drop table 12-register 13-login 14-write file 15-update
- boolean admin = false;
- boolean loggedIn = false;
- boolean debug;
- int userid = -1;
- String username = "";
- String userpass = "";
- String usermail = "";
- String SQLuser = "amaterasu";
- String SQLpw = "access";
- String FTPuser = "web40f7";
- String FTPpw = "access";
- String url ="jdbc:mysql://db4free.net:3306/dict";
- String host = "login-48.hoststar.ch";
- int port = 21;
- static String version = "3.10";
- static String subversion = "900";
- String welcome = "Welcome to Voc v."+version+" build "+subversion+" at "+deb.d.toString()+
- "\nStandard commands:"+
- "\n------------------------------------------------------------------"+
- "\nedit create/edit your own dictionarys"+
- "\n"+
- "\nread reads in a file."+
- "\nwrVoc writes to a voc and erg file."+
- "\n"+
- "\nsql reads from the xprog SQL database."+
- "\ngetSql gets the available dictionarys."+
- "\nwrSql writes to the xprog SQL database."+
- "\ndropSql deletes a dictionary. You can only delete your own dictionarys."+
- "\n"+
- "\nstart starts questioning."+
- "\nstop stops questioning."+
- "\n"+
- "\nupdate checks for updates on the xprog server."+
- "\nusers shows all registred users."+
- "\nregister register an account to upload your own dictionarys."+
- "\nlogin log in to upload your own dictionarys."+
- "\n"+
- "\nadmin Enables admin privilegies. You have to enter a PW."+
- "\ninfo shows the stats."+
- "\ndebug shows the debug console and activates debug mode."+
- "\ndict.info shows info to the dictionary files in the debug console. Debug mode has to be active."+
- "\ndict.print shows the whole dictionary in the debug console. Debug mode hs to be active."+
- "\n------------------------------------------------------------------"+
- "\n";
- //GUI objects
- TimeChk chk = new TimeChk();
- editVoc edit;
- static Info inf;
- static Debug deb;
- JButton set;
- JTextArea out;
- JTextField in;
- //update stuff
- boolean updatebeta = false;
- boolean updateable = false;
- double updatevers = Double.parseDouble(version);
- int updatesubv = Integer.parseInt(subversion);
- int updateprio = 0;
- String updatedesc = "current version";
- //Dictionary stuff
- int trys = 0;
- int debpoint = -1;
- String bk = "";
- String lect = "";
- File voc;
- File erg;
- HashMap<Integer,String> dict = new HashMap<Integer,String>(5000,5000);
- HashMap<Integer,String> sol = new HashMap<Integer,String>(5000,5000);
- Vector<Integer> randoms = new Vector<Integer>(5000);
- int counter = 0;
- //Start action listeners
- class lst implements ActionListener{
- @SuppressWarnings({"deprecation", "deprecation"})
- public void actionPerformed(ActionEvent e){
- if(e.getActionCommand().equalsIgnoreCase("Go")){
- try{
- //updates
- if(stage==15){
- if(updateSql()){
- if(updateable){
- String nachricht="Update available!\ncurrent version:"+version+"."+subversion+"\n\nnew version: \n"+"v. "+updatevers+"."+updatesubv+"\nbeta: "+updatebeta+"\npriority: "+updateprio+"\n\ndescription/changelog:\n"+updatedesc+"\n\n\n Do you want to update?";
- if(JOptionPane.showConfirmDialog(null,nachricht, "Updatemanager", JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE)==JOptionPane.YES_OPTION){
- if(updateFTP())
- outWr("Successfully updated. Please restart application.");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- }
- }else
- JOptionPane.showMessageDialog(null,"No update available.","Updatemanager",JOptionPane.INFORMATION_MESSAGE);
- }else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- stage=0;
- }
- //stats
- if(stage==3){
- inf.setVisible(false);
- inf.counter.suspend();
- inf.timer.suspend();
- outWr("\n\n\nFinished!\nTime needed: "+inf.counter.timem+":"+inf.counter.times+":"+inf.counter.timets);
- if(inf.score.getValue()>0){
- double temp = inf.score.getValue()*100/inf.score.getMaximum();
- outWr("Percentage of correct words: "+temp+"%\n");
- }else
- outWr("You didn't do anything right! Shame on you!\n");
- stage=0;
- }
- //debug
- if(stage==5||debug){
- debpoint=44;
- if(in.getText().equalsIgnoreCase("dict.info")){debWr("voc :"+voc.getAbsolutePath()+"@"+voc.length()+"bytes"+"\nerg :"+erg.getAbsolutePath()+"@"+erg.length()+"bytes\nsize: "+dict.size());in.setText("");}
- if(in.getText().equalsIgnoreCase("dict.print")){for(int i =0;i<dict.size();i++){debWr(dict.get(i)+"\t\t"+sol.get(i));}}
- debpoint=46;
- }
- //readFile
- if(stage==4){
- debpoint=50;
- if(readIn(in.getText()))
- outWr("Succeeded!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- in.setText("");
- stage=0;
- debpoint=57;
- }
- //writeFile
- if(stage==14){
- debpoint=122;
- if(saveOut(in.getText()))
- outWr("Succeeded!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- in.setText("");
- stage=0;
- debpoint=128;
- }
- //read SQL database
- if(stage==6){
- debpoint=96;
- if(readSql(in.getText()))
- outWr("Succeeded!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- stage=0;
- in.setText("");
- debpoint=103;
- }
- //write SQL database
- if(stage==7){
- debpoint=109;
- if(!bk.equals("")&&!lect.equals("")){
- if(createSql(in.getText(),bk,lect))
- outWr("Succeeded!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- stage=0;
- }
- if(!bk.equals("")&&lect.equals("")){
- lect=in.getText();
- outWr("Type in the name of the table.\nThis has nothing to do with the Dictionary.\nPlease use an understandable name.");
- }
- if(bk.equals("")&&lect.equals("")){
- bk=in.getText();
- outWr("Type in the lection numbers, wich this dict includes.");
- }
- in.setText("");
- debpoint=116;
- }
- //get Sql table names
- if(stage==9){
- debpoint=121;
- if(getSql())
- outWr("Succeeded!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- in.setText("");
- stage=0;
- }
- //delete Sql table
- if(stage==11){
- debpoint=132;
- if(dropSql(in.getText()))
- outWr("Succeeded!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- in.setText("");
- stage=0;
- }
- //register
- if(stage==12){
- if(!username.equals("")&&!userpass.equals("")&&usermail.equals("")){
- usermail=in.getText();in.setText("");outWr("Thank you!\nConnecting to server...");
- if(registerSql())
- outWr("Account created!\nYou may now log in!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- stage=0;}
- if(!username.equals("")&&userpass.equals("")){
- userpass=in.getText();in.setText("");outWr("Please enter e-mail adress (optional)");}
- if(username.equals("")){
- username=in.getText();in.setText("");outWr("Please enter desired password");}
- }
- //log in
- if(stage==13){
- debpoint=246;
- if(!username.equals("")&&!userpass.equals("")){
- in.setText("");
- if(verifySql())
- outWr("Logged in!\nYou may now upload dictionarys!\n");
- else
- outWr("Whoops! Something went wrong! Check the debug console!\n");
- stage=0;}
- debpoint=254;
- if(!username.equals("")&&userpass.equals("")){
- userpass=in.getText();set.doClick();}
- debpoint=257;
- if(username.equals("")){
- username=in.getText();in.setText("");outWr("Please enter password");}
- }
- //admin privilegies
- if(stage==10){
- if(in.getText().equalsIgnoreCase("XprogOdbc1")){outWr("Admin mode active!\n");in.setText("");admin=true;}else{outWr("Wrong PW. Sorry.\n");in.setText("");stage=0;}
- }
- //correct
- if(stage==2){
- debpoint=69;
- if(in.getText().equalsIgnoreCase(sol.get(randoms.get(counter)))){
- outWr("That's right!");
- inf.score.setValue(inf.score.getValue()+1);
- trys=0;
- if(counter<dict.size()){
- counter++;stage=1;
- }else{
- stage=3;set.doClick();}
- }else{
- if(trys<3){
- outWr("No. try again.");
- trys++;
- }else{
- trys=0;
- outWr("No. It's "+sol.get(randoms.get(counter)));
- if(counter<dict.size()){
- counter++;stage=1;
- }else{
- stage=3;set.doClick();}
- }
- }
- inf.score.setMaximum(counter);
- inf.scrl.setText(inf.score.getValue()+"/"+counter);
- inf.overall.setValue(counter);
- inf.ovrl.setText(counter+"/"+dict.size());
- }
- //ask
- if(stage==1){
- inf.counter.resume();
- inf.timer.resume();
- debpoint=117;
- inf.timer.timets=inf.timer.times*10+inf.timer.timem*600;
- debpoint=119;
- debpoint=61;
- outWr(dict.get(randoms.get(counter))+" ?");
- in.setText("");
- stage=2;
- }
- //commandline
- if(stage==0||stage==3||stage==4||stage==5){
- //edit the vocabulary
- if(in.getText().equalsIgnoreCase("edit")){outWr("Change/Create dictionary.");in.setText("");
- counter=0;String s="";String d="";String[] data;
- //send data
- while(counter<dict.size()){d=d+"\n"+dict.get(counter);s=s+"\n"+sol.get(counter);counter++;}
- edit.setData(d,s);
- edit.setVisible(true);
- data=edit.getData();
- counter=0;
- dict.clear();sol.clear();
- //save data
- StringTokenizer st = new StringTokenizer(data[0]);
- StringTokenizer s2 = new StringTokenizer(data[1]);
- while(st.hasMoreTokens()){
- dict.put(counter,st.nextToken("\n"));
- sol.put(counter,s2.nextToken("\n"));
- counter++;
- }
- randomSet();
- }
- //jokes ;)
- if(in.getText().equalsIgnoreCase("dini mami")){outWr("Figg dich!");in.setText("");}
- if(in.getText().equalsIgnoreCase("fuck you")){outWr("fuck yourself in your ass!");in.setText("");}
- if(in.getText().equalsIgnoreCase("word")){outWr("woooooord!\nword!\nwooord!!!!111!");in.setText("");}
- if(in.getText().equalsIgnoreCase("your mother")){outWr("your mother is so fat, you turn around and she's still there!");in.setText("");}
- if(in.getText().equalsIgnoreCase("fuck")){outWr("STFU!");in.setText("");}
- if(in.getText().equalsIgnoreCase("scheisse")){outWr("Ja genau, du bisch scheisse!");in.setText("");}
- if(in.getText().equalsIgnoreCase("pensi")){outWr("GNIHIHIHIHI!");in.setText("");}
- if(in.getText().equalsIgnoreCase("penis")){outWr("gnihihihihi!");in.setText("");}
- if(in.getText().equalsIgnoreCase("lol")){outWr("lawl");in.setText("");}
- if(in.getText().equalsIgnoreCase("lawl")){outWr("rofl");in.setText("");}
- if(in.getText().equalsIgnoreCase("rofl")){outWr("lmao");in.setText("");}
- if(in.getText().equalsIgnoreCase("lmao")){outWr("roflmao");in.setText("");}
- if(in.getText().equalsIgnoreCase("roflmao")){outWr("lolroflyfao");in.setText("");}
- if(in.getText().equalsIgnoreCase("lolroflyfao")){outWr("Aha?");in.setText("");}
- if(in.getText().equalsIgnoreCase("gtg")){outWr("Ok... cu");in.setText("");}
- if(in.getText().equalsIgnoreCase("cu")){outWr("bye");in.setText("");}
- if(in.getText().equalsIgnoreCase("bye")){outWr("hehe bye!");in.setText("");}
- if(in.getText().equalsIgnoreCase("stfu")){outWr("I can't even talk, so how should i shut up?\nBesides, you're the one who should shut the fuck up!");in.setText("");}
- if(in.getText().equalsIgnoreCase("...")){outWr("...");in.setText("");}
- if(in.getText().equalsIgnoreCase("wtf")){outWr("Yes, what the fuck are you doing?");in.setText("");}
- if(in.getText().equalsIgnoreCase("omg")){outWr("O my god, you're such a loser!");in.setText("");}
- if(in.getText().equalsIgnoreCase("omfg")){outWr("O my fucking god, you're the biggest loser i've ever seen!");in.setText("");}
- if(in.getText().equalsIgnoreCase("xprog.ch")){outWr("The best website in the whole 42!");in.setText("");}
- if(in.getText().equalsIgnoreCase("the answer to live, the universe and everything")){outWr("42");in.setText("");}
- if(in.getText().equalsIgnoreCase("42")){outWr("is the answer to live, the universe and everything.");in.setText("");}
- if(in.getText().equalsIgnoreCase("google")){outWr("A good searchbot.");in.setText("");}
- if(in.getText().equalsIgnoreCase("onipepper")){outWr("One of the best videogame blogs.");in.setText("");}
- if(in.getText().equalsIgnoreCase("game one")){outWr("One of the best videogame tv shows.");in.setText("");}
- if(in.getText().equalsIgnoreCase("i can has cheezburger?")){outWr("No u canz has cheezburgerz!");in.setText("");}
- if(in.getText().equalsIgnoreCase("!!!!")){outWr("einselfeins");in.setText("");}
- if(in.getText().equalsIgnoreCase("1111")){outWr("!!!!");in.setText("");}
- if(in.getText().equalsIgnoreCase("i hate mondays!")){outWr("hi garfield!");in.setText("");}
- //real commands
- if(in.getText().equalsIgnoreCase("read")){outWr("Reading a dictionary.\nType in the filename.");in.setText("");stage=4;}
- if(in.getText().equalsIgnoreCase("wrVoc")){outWr("Saving a dictionary.\nType in the filename.");in.setText("");stage=14;}
- //sql commands
- if(in.getText().equalsIgnoreCase("sql")){outWr("Reading SQL database.\nType in the table name.");in.setText("");stage=6;}
- if(in.getText().equalsIgnoreCase("wrSql")&&loggedIn){outWr("Saving SQL database.\nType in the name of the book containing the words.");in.setText("");stage=7;String bk = "";String lect = "";}
- if(in.getText().equalsIgnoreCase("getSql")){outWr("Getting available dictionarys...");in.setText("");stage=9;set.doClick();}
- if(in.getText().equalsIgnoreCase("dropSql")&&(admin||loggedIn)){outWr("Dropping a table.\nType in the table name.");in.setText("");stage=11;}
- //user commands
- if(in.getText().equalsIgnoreCase("update")){outWr("Checking for updates.");in.setText("");stage=15;set.doClick();}
- if(in.getText().equalsIgnoreCase("register")&&!loggedIn){outWr("Registring.\nType in your desired username.");in.setText("");stage=12;}
- if(in.getText().equalsIgnoreCase("login")&&!loggedIn){outWr("Logging in.\nType in your username.");in.setText("");stage=13;username="";userpass="";usermail="";}
- if(in.getText().equalsIgnoreCase("users")){outWr("Registred users:\n\n");in.setText("");usersSql();outWr("\n");}
- //special commands
- if(in.getText().equalsIgnoreCase("admin")){outWr("Entering admin mode.\nType in the admin PW.");in.setText("");stage=10;}
- if(in.getText().equalsIgnoreCase("debug")){deb.setVisible(true);stage=5;debug=true;outWr("Entering debug mode");in.setText("");}
- if(in.getText().equalsIgnoreCase("info")){inf.setVisible(true);in.setText("");}
- if(in.getText().equalsIgnoreCase("start")){trys=0;counter=0;inf.counter.timem=0;inf.counter.times=0;inf.counter.timets=0;inf.setVisible(true);randomSet();stage=1;outWr("When you're ready, press GO");in.setText("");}
- }
- //abort questioning
- if(in.getText().equalsIgnoreCase("stop")){stage=0;in.setText("");outWr("Aborted by user action");inf.setVisible(false);inf.counter.suspend();inf.timer.suspend();}
- }catch(Exception f){debWr(f.toString()+" @ "+debpoint);}
- }
- }
- }
- class keys implements KeyListener{
- public void keyTyped(KeyEvent e){}
- public void keyPressed(KeyEvent e){
- if(e.getKeyCode()==KeyEvent.VK_ENTER)
- set.doClick();}
- public void keyReleased(KeyEvent e){}
- }
- //End action listeners
- //Start local functions
- boolean readIn(String name){
- debpoint=105;
- //try to read files
- try{
- voc = new File(name+".voc");
- erg = new File(name+".erg");
- //do these files exist?
- if(!voc.isFile()&&!erg.isFile()){
- debWr("Sorry, the file doesn't exists. @"+debpoint);return(false);}
- //read in
- debpoint=114;
- String puffer;counter=0;
- FileReader leser = new FileReader(voc);
- BufferedReader in = new BufferedReader(leser);
- FileReader leser2 = new FileReader(erg);
- BufferedReader in2 = new BufferedReader(leser2);
- while((puffer=in.readLine())!=null){
- debpoint=121;
- dict.put(counter,puffer);
- sol.put(counter,in2.readLine());
- counter++;
- }
- randomSet();
- debWr("Files read in successful. "+counter+" lines per file.");
- leser.close();leser2.close();
- debpoint=127;
- //set Maximum of progress bar
- inf.overall.setMaximum(counter);
- debpoint=143;
- }catch(Exception e){debWr(e.toString()+" @"+debpoint);return(false);}
- return(true);
- }
- boolean saveOut(String name){
- try{
- debpoint=324;
- FileWriter fw = new FileWriter(name+".voc");
- PrintWriter pw = new PrintWriter(fw);
- FileWriter f2 = new FileWriter(name+".erg");
- PrintWriter p2 = new PrintWriter(f2);
- debpoint=329;
- counter=0;
- while(counter<dict.size()){
- pw.println(dict.get(counter));
- p2.println(sol.get(counter));
- counter++;
- }
- debpoint=335;
- pw.close();
- p2.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- //End local functions
- //Start writing functions
- void outWr(String in){
- out.setText(out.getText()+"\n"+in);
- }
- void debWr(String in){
- deb.output.setText(deb.output.getText()+"\n"+in);
- }
- //End writing functions
- //Start MySQL functions
- boolean getSql(){
- try{
- debpoint=253;
- ResultSet rs;
- Statement stmt;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT * FROM dicts");
- debpoint=254;
- outWr("\n--------------------------------------"+
- "\n|name\tbook\tlections\t|" +
- "\n--------------------------------------");
- while(rs.next()){
- outWr("|"+rs.getString("name")+"\t"+rs.getString("book")+"\t"+rs.getString("lections")+"\t|");
- debpoint=256;
- }
- outWr("--------------------------------------");
- con.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- boolean readSql(String table){
- try{
- debpoint=221;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- debpoint=232;
- stmt = con.createStatement();
- //get the data
- rs = stmt.executeQuery("SELECT * " +"from "+table);
- counter=0;
- while(rs.next()){
- debpoint=241;
- dict.put(counter,rs.getString("q"));
- sol.put(counter,rs.getString("a"));
- counter++;
- }
- outWr("Dictionary created by: "+rs.getString("name"));
- randomSet();
- debpoint=242;
- con.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- boolean createSql(String table,String book,String lection){
- try{
- debpoint=243;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- debpoint=232;
- stmt = con.createStatement();
- //create table
- stmt.executeUpdate("CREATE TABLE "+table+"(version TEXT,q TEXT,a TEXT,name TEXT)");
- //update table list.
- PreparedStatement pstmt = con.prepareStatement("INSERT INTO dicts VALUES(?,?,?)");
- pstmt.setString(1,table);
- pstmt.setString(2,book);
- pstmt.setString(3,lection);
- pstmt.executeUpdate();
- //save voc data
- counter=0;
- while(counter<dict.size()){
- pstmt = con.prepareStatement("INSERT INTO "+table+" VALUES(?,?,?,?)");
- pstmt.setString(1,version);
- pstmt.setString(2,dict.get(counter));
- pstmt.setString(3,sol.get(counter));
- pstmt.setString(4,username);
- pstmt.executeUpdate();
- counter++;
- }
- //update user data
- rs = stmt.executeQuery("SELECT * FROM users WHERE users.name = '"+username+"'");
- while(rs.next()){
- pstmt = con.prepareStatement("UPDATE users SET dicts = ?");
- pstmt.setInt(1,rs.getInt("dicts")+1);
- }
- bk = "";
- lect="";
- con.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- boolean dropSql(String table){
- try{
- debpoint=388;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- debpoint=232;
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT * FROM "+table);
- while(rs.next()){
- if(rs.getString("name").equals(username)||admin){
- //drop the table and delete from dicts list.
- stmt.executeUpdate("DROP TABLE "+table);
- PreparedStatement pstmt = con.prepareStatement("DELETE FROM 'dicts' WHERE 'dicts'.'name' = ?");
- pstmt.setString(1,table);
- pstmt.executeUpdate();
- //update user data
- ResultSet rs2 = stmt.executeQuery("SELECT * FROM users WHERE users.name = '"+username+"'");
- debpoint=402;
- while(rs2.next()){
- pstmt = con.prepareStatement("UPDATE users SET dicts = ?");
- pstmt.setInt(1,rs.getInt("dicts")+1);
- pstmt.executeUpdate();
- }
- }else{
- outWr("You don't have the rights to delete this table.");return(false);
- }
- }
- con.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- boolean registerSql(){
- try{
- debpoint=389;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- debpoint=390;
- stmt = con.createStatement();
- // id,name,pass,mail,date,dicts
- PreparedStatement PStmt = con.prepareStatement("INSERT INTO users VALUES(?,?,?,?,NOW(),?)");
- PStmt.setInt(1,0);
- PStmt.setString(2,username);
- PStmt.setString(3,userpass);
- PStmt.setString(4,usermail);
- PStmt.setInt(5,0);
- PStmt.executeUpdate();
- debpoint=401;
- con.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- boolean verifySql(){
- try{
- debpoint=402;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- debpoint=408;
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT * FROM users");
- counter=0;
- while(rs.next()){
- if(rs.getString("name").equals(username)&&rs.getString("pass").equals(userpass)){userid=rs.getInt("id");loggedIn=true;break;}
- }
- con.close();
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- if(loggedIn)
- return(true);
- else
- return(false);
- }
- boolean usersSql(){
- try{
- debpoint=472;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- debpoint=479;
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT * FROM users");
- while(rs.next()){
- outWr(rs.getInt("id")+"-"+rs.getString("name")+" member since: "+rs.getString("reg_date")+" dictionarys uploaded: "+rs.getString("dicts"));
- }
- debpoint=488;
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- boolean updateSql(){
- try{
- debpoint=603;
- Statement stmt;
- ResultSet rs;
- Connection con = DriverManager.getConnection(url,SQLuser, SQLpw);
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT * FROM version");
- debpoint=612;
- while(rs.next()){
- if(rs.getString("program").equals("Voc")){
- if(rs.getDouble("version")>updatevers){
- updateable = true;
- updatevers = rs.getDouble("version");
- updateprio = rs.getInt("priority");
- updatesubv = rs.getInt("subversion");
- updatedesc = rs.getString("description");
- if(rs.getInt("beta")>0)
- updatebeta=true;
- else
- updatebeta=false;
- }
- }
- }
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- //End MySQL functions
- //Start FTP functions
- boolean updateFTP(){
- try{
- debpoint=658;
- FTPClient client = new FTPClient();
- client.connect(host, port);
- debpoint=662;
- if(client.login(FTPuser, FTPpw)) {
- //download
- File file = new File("update.zip");
- FileOutputStream dfile = new FileOutputStream(file);
- client.retrieveFile("/upd/"+updatevers+"-"+updatesubv+"/voc.zip",dfile);
- debpoint=669;
- dfile.close();
- client.disconnect();
- //unzip
- final int BUFFER = 2048;
- BufferedOutputStream dest = null;
- FileInputStream fis = new FileInputStream("update.zip");
- ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
- ZipEntry entry;
- while((entry = zis.getNextEntry()) != null) {
- debpoint=677;
- System.out.println("Extracting: " +entry);
- int count;
- byte data[] = new byte[BUFFER];
- // write the files to the disk
- FileOutputStream fos = new FileOutputStream(entry.getName());
- dest = new BufferedOutputStream(fos, BUFFER);
- while ((count = zis.read(data, 0, BUFFER)) != -1) {
- debpoint=685;
- dest.write(data, 0, count);
- }
- dest.flush();
- dest.close();
- }
- zis.close();
- }
- debpoint=691;
- }catch(Exception e){debWr(e.toString()+" @ "+debpoint);return(false);}
- return(true);
- }
- //End FTP functions
- //other functions and classes
- void randomSet(){
- Random gen = new Random();
- randoms = new Vector<Integer>(5000);
- if(dict.size()>0){
- randoms.add(gen.nextInt(dict.size()));
- debpoint=131;
- for(int i=0;i<dict.size();i++){
- int ch = gen.nextInt(dict.size()+1)-1;
- debpoint=134;
- while(randoms.contains(ch))
- ch=gen.nextInt(dict.size()+1)-1;
- debpoint=137;
- randoms.add(ch);
- }}
- randoms.add(10);
- }
- class TimeChk extends Thread{
- public void run(){
- while(!isInterrupted()){
- try{
- if(inf.timer.timets<=0){
- trys++;set.doClick();}
- deb.data.setText("stage: "+stage+"\ttrys: "+trys+"\nWord: "+randoms.get(counter)+"\tcounter: "+counter+"\nLogged in: "+loggedIn+"\nusername: "+username+"\tuserpass: "+userpass+"\tusermail: "+usermail+"\ndebpoint: "+debpoint);
- Thread.sleep(200);}catch(Exception e){debWr(e.toString()+" @ "+debpoint);}
- }
- }
- }
- //Main frame settings
- @SuppressWarnings("deprecation")
- Voc(String title){
- super(title);
- stage=0;
- edit = new editVoc(this,"Voc-editor",true,ew,eh);
- edit.setLocation(w+10+iw+10,0);
- chk.start();
- inf.counter.start();
- inf.counter.suspend();
- inf.timer.start();
- inf.timer.suspend();
- randomSet();
- setLayout(null);
- in=new JTextField();
- set=new JButton("Go");
- out=new JTextArea(welcome);
- JScrollPane scr = new JScrollPane(out);
- out.setEditable(false);
- scr.setBounds(0,0,w,h-50);
- set.setBounds(w-50,h-50,50,50);
- in.setBounds(0,h-50,w-50,50);
- add(set);
- add(scr);
- add(in);
- set.addKeyListener(new keys());
- scr.addKeyListener(new keys());
- in.addKeyListener(new keys());
- set.addActionListener(new lst());
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- }
- public static void main(String[] args){
- inf = new Info(iw,ih);
- deb = new Debug(dw,dh);
- Voc hpt = new Voc(version);
- inf.setSize(iw+10,ih+35);
- hpt.setSize(w+10,h+25);
- deb.setSize(dw+10,dh+25);
- deb.setLocation(w+10,0);
- inf.setLocation(w+10,dh+25);
- hpt.setVisible(true);
- deb.setVisible(false);
- inf.setVisible(false);
- try{DriverManager.registerDriver(new com.mysql.jdbc.Driver());}catch(Exception e){e.printStackTrace();}
- }
- }
- //debug console
- class Debug extends JFrame{
- JTextArea output;
- JTextArea data;
- java.util.Date d = new java.util.Date();
- Debug(int dw,int dh){
- super("Debug console");
- setLayout(null);
- data=new JTextArea("");
- output = new JTextArea("Debug console started on "+d.toString());
- data.setEditable(false);
- output.setEditable(false);
- JScrollPane scroll = new JScrollPane(output);
- JScrollPane scrol2 = new JScrollPane(data);
- scroll.setBounds(0,0,dw,dh);
- scrol2.setBounds(0,dh,dw,(dh)/2);
- add(scroll);
- add(scrol2);
- setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
- }
- }
- //edit voc console
- class editVoc extends JDialog implements ActionListener{
- JTextArea dict = null;
- JTextArea sol = null;
- JButton set = null;
- private boolean okStatus = false;
- public editVoc(Frame besitzer, String titel,boolean modal,int ew,int eh){
- super(besitzer, titel, modal);
- setSize(ew+10,eh+25);
- Container cp = getContentPane();
- cp.setLayout(null);
- dict = new JTextArea();
- sol = new JTextArea();
- set = new JButton("Done!");
- JScrollPane scr = new JScrollPane(dict);
- JScrollPane sc2 = new JScrollPane(sol);
- scr.setBounds(0,0,Math.round(ew/2)-3,eh-50);
- sc2.setBounds(Math.round(ew/2)+3,0,Math.round(ew/2)-3,eh-50);
- set.setBounds(0,eh-50,ew,50);
- add(scr);
- add(sc2);
- add(set);
- set.addActionListener(this);
- }
- public String[] getData(){
- if(okStatus==true){
- String[] result = new String[2];
- int i=0;
- result[0]=dict.getText();
- result[1]=sol.getText();
- return(result);
- }else{
- return null;
- }
- }
- public void setData(String d,String s){
- dict.setText(d);
- sol.setText(s);
- }
- public static String[] showDialog(Frame f, String titel,int ew, int eh){
- editVoc edit = new editVoc(f,titel,true,ew,eh);
- edit.setVisible(true);
- return(edit.getData());
- }
- public void actionPerformed(ActionEvent e){
- okStatus=true;
- setVisible(false);
- }
- }
- //info frame
- class Info extends JFrame{
- JProgressBar time;
- JProgressBar score;
- JProgressBar overall;
- JLabel timl;
- JLabel scrl;
- JLabel ovrl;
- Timer counter;
- Timer timer;
- Info(int iw,int ih){
- super("Info");
- setLayout(null);
- timl=new JLabel("-:-");
- scrl=new JLabel("-/-");
- ovrl=new JLabel("-/-");
- time=new JProgressBar();
- score=new JProgressBar();
- overall=new JProgressBar();
- time.setBounds(10,ih/6,iw-20,ih/6);
- score.setBounds(10,ih/2,iw-20,ih/6);
- overall.setBounds(10,ih/6*5,iw-20,ih/6);
- timl.setBounds(10,0,iw-20,ih/6);
- scrl.setBounds(10,ih/6*2,iw-20,ih/6);
- ovrl.setBounds(10,ih/6*4,iw-20,ih/6);
- add(time);
- add(score);
- add(overall);
- add(timl);
- add(scrl);
- add(ovrl);
- time.setMinimum(0);
- score.setMinimum(0);
- overall.setMinimum(0);
- overall.setString("Overall");
- score.setString("Score");
- time.setString("Time");
- timer = new Timer(false,0,20,0);
- counter = new Timer(true,0,0,0);
- setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
- }
- //timer
- class Timer extends Thread{
- int timets,times,timem;boolean count = false;
- Timer(boolean mode,int tts,int ts, int tm){
- count=mode;
- timets=tts;times=ts;timem=tm;
- if(!count){
- timets+=times*10+timem*600;
- time.setMaximum(timets);}
- }
- public void run(){
- while(isInterrupted()==false){
- try{
- if(count){
- timets++;
- if(timets>=10){times++;timets=0;}
- if(times>=60){timem++;times=0;}
- timl.setText(timem+":"+times+":"+timets);
- }else{
- timets--;
- time.setValue(timets);
- }
- Thread.sleep(100);}catch(Exception e){}
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment