da ich wie versprochen die Systeme, die mir sinnvoll erscheinen, programmieren und releasen werde, habe ich hier nun das erste fertige System für euch.
Weitere Vorschläge werden gerne entgegen genommen (:
Das System ist ein Couponsystem.
Das Team erstellt Coupons die via eigenem E-Mail Script, Forum oder sonst wie verbreitet werden können.
Anschließend hat der Benutzer die Möglichkeit diesen Coupon einzulösen. Aktuell sind die Währung Item, Donate Coin und Vote Coin enthalten.
Bei Vorschlägen zu weiteren Währungen bitte einfach im Thread melden.
Bei Vorschlägen zu neuen Systeme oder Fragen zu diesen bitte ebenfalls einfach posten (:
Der Source Code zu dem ganzen Spaß findet sich im Anhang.
Das System lässt sich mit JEDER Webseite kombinieren egal ob es nun eine alte Stefan Pfeifer, die Sapphiere Flyff oder eine eigene Webseite ist.
Hier noch ein Video:
Coupon.Config.php
PHP Code:
<?php
session_start();
$_SESSION['user'] = 'krmlf';
define('WEBSITE_DATABASE', 'WEBSITE_DBF'); //Name of your website database
define('COUPON_TABLE_DBF', 'FLYFF'); //Name of the database where the coupon table is
define('DONATE_COIN_TABLE', 'WebAccount'); //Table where the donate coins are saved
define('VOTE_COIN_TABLE', 'WebAccount'); //Table where the vote coins are saved
define('DONATE_COIN_ROW', 'dcoins'); //Row where the value of the donate coins is saved
define('VOTE_COIN_ROW', 'vcoins'); //Row where the value of the vote coins is saved
define('SESSION_USER', 'user'); //Session Key like $_SESSION['user'] "user" which is used for the account name by your session
//define strict standards
$mssqlCredentialsArray = array(
'Host' => 'ANDY\SQLEXPRESS',
'User' => '',
'Pass' => '',
);
$sql = @odbc_connect('Driver={SQL Server};Server=' . $mssqlCredentialsArray['Host'] . ';Port=1433', $mssqlCredentialsArray['User'], $mssqlCredentialsArray['Pass']);
//load files
require_once('Class.Coupon.php');
$create = new Coupon($sql);
//call class "Coupon"
$couponSystem = new Coupon($sql);
Class.Coupon.php #updated 12.10.2015
PHP Code:
<?php
class Coupon extends Validation {
private $sql;
function __construct($sql){
$this->sql = $sql;
}
private function SetCoupon($event, $i){
return strtoupper(md5(time().microtime().rand(1, 1000000000).$i.$event));
}
private function SetCouponCredentials($post, $account){
$couponCredentials = array(
'schedule' => $post['schedule'],
'expire' => time() + intval($post['expire'])*24*60*60,
'value' => intval($post['value']),
'amount' => intval($post['amount']),
'event' => $post['event'],
'account' => $account,
);
return $couponCredentials;
}
private function InsertCouponIntoDatabase($coupon, $key){
$coupon = self::Escape($coupon);
self::Exec($this->sql, 'INSERT INTO [' . COUPON_TABLE_DBF . '].[dbo].[Coupon] ([schedule], [coupon], [expire], [account], [value], [used], [event]) VALUES (' . $coupon['schedule'] . ', \'' . $key . '\', ' . $coupon['expire'] . ', ' . $coupon['account'] . ', ' . $coupon['value'] . ', 0, ' . $coupon['event'] . ')');
if(odbc_error()){echo odbc_errormsg($this->sql);}
}
//CREATE COUPON
public function CreateCoupon($post){
//If button is not pressed
if(!isset($post['create'])){return false;}else{unset($post['create']);}
//Save account
if(!empty($post['account'])){
$account = $post['account'];
}else {
$account = 0;
}
unset($post['account']);
//If some fields are empty
if(self::EmptyInput($post) === 0){echo 'Please fill in all fields'; exit;}
//Set Coupon Credentials
$coupon = self::SetCouponCredentials($post, $account);
//Generate Keys
$key = array();
for($k = 1;$k <= $coupon['amount'];$k++){
$key[$k] = self::SetCoupon($post['event'], $k);
}
//Insert Coupon into database
for($i = 1;$i <= $coupon['amount'];$i++){
self::InsertCouponIntoDatabase($coupon, $key[$i]);
}
}
//SELECT ALL COUPONS
private function GetAllCoupons(){
$coupons = self::Exec($this->sql, 'SELECT * FROM ' . COUPON_TABLE_DBF . '.dbo.Coupon');
return $coupons;
}
public function SelectAllCoupons(){
$coupons = array();
$coupons['Rows'] = self::Rows(self::GetAllCoupons());
$coupons['Result'] = self::Fetch(self::GetAllCoupons(), $coupons['Rows']);
return $coupons;
}
//DELETE ALL EXPIRED COUPONS
public function DeleteAllExpiredCoupons($post){
if(!isset($post['deleteall'])){return false;}
self::Exec($this->sql, 'DELETE FROM ' . COUPON_TABLE_DBF . '.dbo.Coupon WHERE expire < ' . time());
}
//SELECT EVENT COUPONS
private function GetCouponsBySpecificEvent($post){
$post = self::Escape($post);
$coupons = self::Exec($this->sql, 'SELECT * FROM ' . COUPON_TABLE_DBF . '.dbo.Coupon WHERE [event] = ' . $post['event']);
return $coupons;
}
public function SelectEventCoupons($post){
if(!isset($post['eventcoupons'])){return false;}
if(self::EmptyInput($post) === 0){echo 'Please fill in all fields'; exit;}
$coupons = array();
$coupons['Rows'] = self::Rows(self::GetCouponsBySpecificEvent($post));
if($coupons['Rows'] > 0){
$coupons['Result'] = self::Fetch(self::GetCouponsBySpecificEvent($post), $coupons['Rows']);
}else {
echo 'No coupons found.'; exit;
}
return $coupons;
}
//USE COUPONS
private function GetUsersSpecificCoupon($post, $account){
$post = self::Escape($post);
$coupon = self::Exec($this->sql, 'SELECT * FROM ' . COUPON_TABLE_DBF . '.dbo.Coupon WHERE [coupon] = ' . $post['coupon']);
return $coupon;
}
private function GetSpecificReward($schedule, $value, $player, $account, $coupon){
self::Exec($this->sql, 'UPDATE [' . COUPON_TABLE_DBF . '].[dbo].[Coupon] SET [used] = 1 WHERE [coupon] = \'' . $coupon . '\'');
self::Exec($this->sql, 'UPDATE [' . COUPON_TABLE_DBF . '].[dbo].[Coupon] SET [account] = \'' . $account . '\' WHERE [coupon] = \'' . $coupon . '\'');
switch($schedule){
case 'item':
self::Exec($this->sql, 'INSERT INTO [CHARACTER_01_DBF].[dbo].[ITEM_SEND_TBL] ([m_idPlayer], [serverindex], [Item_Name], [Item_count], [idSender]) VALUES (\'' . $player . '\', \'01\', \'' . $value . '\', 1, \'0000000\')');
break;
case 'dcoins':
$old = self::Fetch(self::Exec($this->sql, 'SELECT [' . DONATE_COIN_ROW . '] FROM [' . WEBSITE_DATABASE . '].[dbo].[' . DONATE_COIN_TABLE . '] WHERE [username] = \'' . $account . '\''), 1);
$old = intval($old[1][DONATE_COIN_ROW]);
$new = intval($value) + intval($old);
self::Exec($this->sql, 'UPDATE [' . WEBSITE_DATABASE . '].[dbo].[' . DONATE_COIN_TABLE . '] SET [' . DONATE_COIN_ROW . '] = ' . $new . ' WHERE [username] = \'' . $account . '\'');
break;
case 'vcoins':
$old = self::Fetch(self::Exec($this->sql, 'SELECT [' . VOTE_COIN_ROW . '] FROM [' . WEBSITE_DATABASE . '].[dbo].[' . VOTE_COIN_TABLE . '] WHERE [username] = \'' . $account . '\''), 1);
$old = intval($old[1][VOTE_COIN_ROW]);
$new = intval($value) + intval($old);
self::Exec($this->sql, 'UPDATE [' . WEBSITE_DATABASE . '].[dbo].[' . VOTE_COIN_TABLE . '] SET [' . VOTE_COIN_ROW . '] = ' . $new . ' WHERE [username] = \'' . $account . '\'');
break;
}
}
public function GetCharacterByAccount(){
$account = $_SESSION[SESSION_USER];
$chars = self::Exec($this->sql, 'SELECT [m_idPlayer], [m_szName] FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [account] = \'' . $account. '\' AND [isblock] = \'F\'');
$rows = self::Rows($chars);
if($rows <= 0){die('You have to create a character before you can use a coupon.');}
$result = self::Fetch($chars, $rows);
return $result;
}
public function UseCoupon($post){
$account = $_SESSION[SESSION_USER];
if(!isset($post['usecoupon'])){return false;}
if(self::EmptyInput($post) === 0){echo 'Please fill in all fields'; exit;}
$coupon = self::GetUsersSpecificCoupon($post, $account);
$arr = array();
$arr['Rows'] = self::Rows($coupon);
if($arr['Rows'] > 0){
$arr['Result'] = self::Fetch($coupon, $arr['Rows']);
if(intval($arr['Result'][1]['expire']) >= time()){
if(intval($arr['Result'][1]['used']) === 0){
if($arr['Result'][1]['account'] === '0'){
$characterSave = $post['character'];
$post = self::Escape($post);
$charlength = strlen($characterSave);
$str = null;
for($i = 1;$i <= 7-intval($charlength);$i++){
$str .= '0';
}
$str .= $characterSave;
echo $str;
self::GetSpecificReward($arr['Result'][1]['schedule'], $arr['Result'][1]['value'], $str, $account, $arr['Result'][1]['coupon']);
echo 'Item has been send to your character.'; exit;
}else {
if($arr['Result'][1]['account'] === $account){
self::GetSpecificReward($arr['Result'][1]['schedule'], $arr['Result'][1]['value'], $post['character'], $account, $arr['Result'][1]['coupon']);
echo 'Item has been send to your character.'; exit;
}else {
echo 'This coupon is reserved for another player.'; exit;
}
}
}else {
echo 'Coupon was already used by another player.'; exit;
}
}else {
echo 'Coupon has been expired.'; exit;
}
}else {
echo 'Coupon not found.'; exit;
}
}
}
class Validation {
public static function EmptyInput($array){
$result = 1;
foreach($array as $key => $value){
if(empty($array[$key])){
return $result = 0;
}
}
return $result;
}
protected function Escape($array){
foreach($array as $key => $value){
if(gettype($value) != 'integer' && $value !== null){
$array[$key] = '0x'.bin2hex($value);
}else {
$array[$key] = $value;
}
}
return $array;
}
protected function Exec($sql, $qry){
$exec = @odbc_exec($sql, $qry);
if(odbc_error()){echo odbc_errormsg($sql);}
return $exec;
}
protected function Rows($rlt){
return @odbc_num_rows($rlt);
}
protected function Fetch($rlt, $rows){
$arr = array();
for($i = 1;$i <= $rows;$i++){
$arr[$i] = @odbc_fetch_array($rlt, $i);
}
return $arr;
}
}






