contract ARK_FLAGGER_1_00{

  ARK Ark;
  ARKController_1_00 ARKcontroller;
  address owner;
  ARK_VOTER_1_00 ARKvoter;

  struct BlackFlag{
  uint blackflagrequest;
  uint blackflags;
  }

    mapping(uint => BlackFlag) blackflags;


    mapping(uint => Censorship)censoring;
    struct Censorship{mapping(address => bool) censor;}

   uint[] thresold;

    
  
////////////////////////////////////////////////
    log[] logs;

    struct log{
    address admin;
    string action;
    address addr;
    uint i;
    }
////////////////////////////////////////////////

   function ARK_FLAGGER_1_00(){

   owner=msg.sender;
   
   thresold.push(3);
   thresold.push(3);
   thresold.push(3);
   thresold.push(3);
   thresold.push(3);
   thresold.push(3);
   }

  

    function setOwner(address a) {
    if(msg.sender!=owner)throw;
    owner=a;
    logs.push(log(owner,"setOwner",a,0));
    }

    function setController(address a) {
    if(msg.sender!=owner)throw;
    ARKcontroller=ARKController_1_00(a);
    logs.push(log(owner,"setController",a,0));
    }

    function setVoter(address a) {
    if(msg.sender!=owner)throw;
    ARKvoter=ARK_VOTER_1_00(a);
    logs.push(log(owner,"setVoter",a,0));
    }


    function setSource(address a) {
    if(msg.sender!=owner)throw;
    Ark=ARK(a);
    logs.push(log(owner,"setSource",a,0));
    }

    function readLog(uint i)constant returns(address,string,address,uint){
    log l=logs[i];
    return(l.admin,l.action,l.addr,l.i);
    }

    function check()constant returns(bool){
        var b=false;
        if(Ark.getOwnedBot(msg.sender,0)>0)b=true;
        return b;
       
    }

        function setBlackflag(uint i,bool b){if(msg.sender!=owner)throw;if(b){blackflags[i].blackflags++;}else{blackflags[i].blackflags--;}}




        function setBlackFlagRequest(uint index,uint typ){
 
        var (x,y) = Ark.getCoinStats(0);
        BlackFlag c = blackflags[index];
        
        if((index<=y)&&(check())&&((typ==1)||(typ==1001)||(typ==10001))&&(!censoring[index].censor[msg.sender])){
        if(c.blackflagrequest==0){censoring[index]=Censorship(); c.blackflagrequest=typ;}
        logs.push(log(msg.sender,"requestBlackFlag",0x0,index));
        censoring[index].censor[msg.sender]=true;      
        }else{throw;}
        }




       function getBlackflag(uint index,address a) constant returns(bool,uint,uint){
        BlackFlag c = blackflags[index];
        return (censoring[index].censor[a],c.blackflagrequest,c.blackflags);
        }

        function confirmBlackFlag(uint index,bool confirm){
        BlackFlag c = blackflags[index];
        uint t=c.blackflagrequest;

        
        if((check())&&(t>=1)&&(!censoring[index].censor[msg.sender])){
            if(confirm){
        
               if((t<(1+thresold[0]))||((1000<t)&&(t<(1001+thresold[0])))||((t>10000)&&(t<(10000+thresold[1])))){
                  c.blackflagrequest++;
                  //censoring[index].blackflagasker=msg.sender;
                  censoring[index].censor[msg.sender]=true;
               }else{   
                   if(t>=10000+thresold[1]){
                    ARKcontroller.applyCensorship(index);
                    censoring[index]=Censorship();
                   }else{                      
                    c.blackflags++;     
                   } 
                   c.blackflagrequest=0;
               }      
            }else{if(t>10000){c.blackflagrequest=0;logs.push(log(msg.sender,"nullCensorshipRequest",0x0,index));}else{c.blackflagrequest--;}}
        }else{throw;}
        }


        function setThresold(uint i,uint j){
        if(msg.sender!=owner)throw;
        thresold[i]=j;
 
        if(i==0)logs.push(log(owner,"setThresold0",0x0,j));
        if(i==1)logs.push(log(owner,"setThresold1",0x0,j));
        if(i==2)logs.push(log(owner,"setThresold2",0x0,j));
        if(i==3)logs.push(log(owner,"setThresold3",0x0,j));
        if(i==4)logs.push(log(owner,"setThresold4",0x0,j));
        if(i==5)logs.push(log(owner,"setThresold5",0x0,j));
        }

        function updateThresold(uint i){
        thresold[i]=ARKvoter.getThresold(i);
        //uint u=ARKvoter.getThresold(i);
        if(i==0)logs.push(log(owner,"updateThresold0",0x0,i));
        if(i==1)logs.push(log(owner,"updateThresold1",0x0,i));
        if(i==2)logs.push(log(owner,"updateThresold2",0x0,i));
        if(i==3)logs.push(log(owner,"updateThresold3",0x0,i));
        if(i==4)logs.push(log(owner,"updateThresold4",0x0,i));
        if(i==5)logs.push(log(owner,"updateThresold5",0x0,i));
        }

        function getThresold()constant returns(uint,uint,uint,uint,uint,uint){
        return (thresold[0],thresold[1],thresold[2],thresold[3],thresold[4],thresold[5]);
        }


}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ARK_FLAGGER_1_00(){

owner=msg.sender;
   
thresold.push(3);
thresold.push(3);
thresold.push(3);
thresold.push(3);
thresold.push(3);
thresold.push(3);
}

////////////////////////////////////////////////